<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1" />
<meta name="generator" content="pdoc 0.10.0" />
<title>Euro-Truck-Simulator-2-Lane-Assist.plugins.TrafficLightDetection.main API documentation</title>
<meta name="description" content="This is an example of a plugin (type=&#34;dynamic&#34;), they will be updated during the stated point in the mainloop.
If you need to make a panel that is …" />
<link rel="preload stylesheet" as="style" href="https://cdnjs.cloudflare.com/ajax/libs/10up-sanitize.css/11.0.1/sanitize.min.css" integrity="sha256-PK9q560IAAa6WVRRh76LtCaI8pjTJ2z11v0miyNNjrs=" crossorigin>
<link rel="preload stylesheet" as="style" href="https://cdnjs.cloudflare.com/ajax/libs/10up-sanitize.css/11.0.1/typography.min.css" integrity="sha256-7l/o7C8jubJiy74VsKTidCy1yBkRtiUGbVkYBylBqUg=" crossorigin>
<link rel="stylesheet preload" as="style" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/10.1.1/styles/ir-black.min.css" crossorigin>
<style>
:root {
--highlight-color: #202;
}
html {
scrollbar-face-color: #646464;
scrollbar-base-color: #646464;
scrollbar-3dlight-color: #646464;
scrollbar-highlight-color: #646464;
scrollbar-track-color: #000;
scrollbar-arrow-color: #000;
scrollbar-shadow-color: #646464;
scrollbar-dark-shadow-color: #646464;
}
::-webkit-scrollbar { width: 14px; height: 3px;}
::-webkit-scrollbar-button {
background-color: #000;
height: 3px;}
::-webkit-scrollbar-track {
background-color: #646464;}
::-webkit-scrollbar-track-piece { background-color: #000;}
::-webkit-scrollbar-thumb { height: 50px; background-color: #666; border-radius: 7px;}
::-webkit-scrollbar-corner { background-color: #646464;}
::-webkit-resizer { background-color: #666;}
.flex {
display: flex !important;
}
body {
line-height: 1.5em;
color: #fff;
background-color: #1e1e1e;
font: 14px/1.5 Helvetica, Arial, sans-serif;
margin: 0;
padding: 0;
}
#content {
padding: 20px;
}
#sidebar {
padding: 30px;
overflow: hidden;
}
#sidebar>*:last-child {
margin-bottom: 2cm;
}
.http-server-breadcrumbs {
font-size: 130%;
margin: 0 0 15px 0;
}
#footer {
font-size: .75em;
padding: 5px 30px;
border-top: 1px solid #fff;
text-align: right;
}
#footer p {
margin: 0 0 0 1em;
display: inline-block;
}
#footer p:last-child {
margin-right: 30px;
}
h1,
h2,
h3,
h4,
h5 {
font-weight: 300;
color: #fff;
}
h1 {
font-size: 2.5em;
line-height: 1.1em;
}
h2 {
font-size: 1.75em;
margin: 1em 0 .50em 0;
}
h3 {
font-size: 1.4em;
margin: 25px 0 10px 0;
}
h4 {
margin: 0;
font-size: 105%;
}
h1:target,
h2:target,
h3:target,
h4:target,
h5:target,
h6:target {
background: #1e1e1e;
padding: 0.2em 0;
}
a {
color: #8fd6fc;
text-decoration: none;
transition: color .3s ease-in-out;
}
a:hover {
color: #00a4fc;
}
.title code {
font-weight: bold;
}
h2[id^="header-"] {
margin-top: 2em;
}
.ident {
color: #f6fc85;
}
strong {
color: #8fd6fc;
}
pre code {
background: transparent;
font-size: .8em;
line-height: 1.4em;
}
code {
background: rgba(255, 255, 255, 0.1);
padding: 1px 4px;
overflow-wrap: break-word;
}
h1 code {
background: transparent
}
pre {
background: transparent;
border: 0;
border-top: 1px solid #ccc;
border-bottom: 1px solid #ccc;
margin: 1em 0;
padding: 1ex;
}
#http-server-module-list {
display: flex;
flex-flow: column;
}
#http-server-module-list div {
display: flex;
}
#http-server-module-list dt {
min-width: 10%;
}
#http-server-module-list p {
margin-top: 0;
}
.toc ul,
#index {
list-style-type: none;
margin: 0;
padding: 0;
}
#index code {
background: transparent;
}
#index h3 {
border-bottom: 1px solid #ddd;
}
#index ul {
padding: 0;
}
#index h4 {
margin-top: .6em;
font-weight: bold;
}
/* Make TOC lists have 2+ columns when viewport is wide enough.
Assuming ~20-character identifiers and ~30% wide sidebar. */
@media (min-width: 200ex) {
#index .two-column {
column-count: 2
}
}
@media (min-width: 300ex) {
#index .two-column {
column-count: 3
}
}
dl {
margin-bottom: 2em;
}
dl dl:last-child {
margin-bottom: 4em;
}
dd {
margin: 0 0 1em 3em;
}
#header-classes+dl>dd {
margin-bottom: 3em;
}
dd dd {
margin-left: 2em;
}
dd p {
margin: 10px 0;
}
.name {
background: #000;
font-weight: bold;
font-size: .85em;
padding: 5px 10px;
display: inline-block;
min-width: 40%;
}
.name:hover {
background: #0b0b0b;
}
dt:target .name {
background: var(--highlight-color);
}
.name>span:first-child {
white-space: nowrap;
}
.name.class>span:nth-child(2) {
margin-left: .4em;
}
.inherited {
color: #999;
border-left: 5px solid #eee;
padding-left: 1em;
}
.inheritance em {
font-style: normal;
font-weight: bold;
}
.pydefname {
color: #f90;
}
/* Docstrings titles, e.g. in numpydoc format */
.desc h2 {
font-weight: 400;
font-size: 1.25em;
}
.desc h3 {
font-size: 1em;
}
.desc dt code {
background: inherit;
/* Don't grey-back parameters */
}
.source summary,
.git-link-div {
color: #666;
text-align: right;
font-weight: 400;
font-size: .8em;
text-transform: uppercase;
}
.source summary>* {
white-space: nowrap;
cursor: pointer;
}
.git-link {
color: inherit;
margin-left: 1em;
}
.source pre {
max-height: 500px;
overflow: auto;
margin: 0;
}
.source pre code {
font-size: 12px;
overflow: visible;
}
.hlist {
list-style: none;
}
.hlist li {
display: inline;
}
.hlist li:after {
content: ',\2002';
}
.hlist li:last-child:after {
content: none;
}
.hlist .hlist {
display: inline;
padding-left: 1em;
}
img {
max-width: 100%;
}
td {
padding: 0 .5em;
}
.admonition {
padding: .1em .5em;
margin-bottom: 1em;
}
.admonition-title {
font-weight: bold;
}
.admonition.note,
.admonition.info,
.admonition.important {
background: #00a;
}
.admonition.todo,
.admonition.versionadded,
.admonition.tip,
.admonition.hint {
background: #050;
}
.admonition.warning,
.admonition.versionchanged,
.admonition.deprecated {
background: #ec0;
}
.admonition.error,
.admonition.danger,
.admonition.caution {
background: #c20010;
}
p {
color: #fff;
}
</style>
<style media="screen and (min-width: 700px)">@media screen and (min-width:700px){#sidebar{width:30%;height:100vh;overflow:auto;position:sticky;top:0}#content{width:70%;max-width:100ch;padding:3em 4em;border-left:1px solid #ddd}pre code{font-size:1em}.item .name{font-size:1em}main{display:flex;flex-direction:row-reverse;justify-content:flex-end}.toc ul ul,#index ul{padding-left:1.5em}.toc > ul > li{margin-top:.5em}}</style>
<style media="print">@media print{#sidebar h1{page-break-before:always}.source{display:none}}@media print{*{background:transparent !important;color:#000 !important;box-shadow:none !important;text-shadow:none !important}a[href]:after{content:" (" attr(href) ")";font-size:90%}a[href][title]:after{content:none}abbr[title]:after{content:" (" attr(title) ")"}.ir a:after,a[href^="javascript:"]:after,a[href^="#"]:after{content:""}pre,blockquote{border:1px solid #999;page-break-inside:avoid}thead{display:table-header-group}tr,img{page-break-inside:avoid}img{max-width:100% !important}@page{margin:0.5cm}p,h2,h3{orphans:3;widows:3}h1,h2,h3,h4,h5,h6{page-break-after:avoid}}</style>
<script defer src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/10.1.1/highlight.min.js" integrity="sha256-Uv3H6lx7dJmRfRvH8TH6kJD1TSK1aFcwgx+mdg3epi8=" crossorigin></script>
<script>window.addEventListener('DOMContentLoaded', () => hljs.initHighlighting())</script>
</head>
<body>
<main>
<article id="content">
<header>
<h1 class="title">Module <code>Euro-Truck-Simulator-2-Lane-Assist.plugins.TrafficLightDetection.main</code></h1>
</header>
<section id="section-intro">
<p>This is an example of a plugin (type="dynamic"), they will be updated during the stated point in the mainloop.
If you need to make a panel that is only updated when it's open then check the Panel example!</p>
<details class="source">
<summary>
<span>Expand source code</span>
</summary>
<pre><code class="python">&#34;&#34;&#34;
This is an example of a plugin (type=&#34;dynamic&#34;), they will be updated during the stated point in the mainloop.
If you need to make a panel that is only updated when it&#39;s open then check the Panel example!
&#34;&#34;&#34;


from plugins.plugin import PluginInformation
from src.logger import print
from src.mainUI import switchSelectedPlugin, resizeWindow

PluginInfo = PluginInformation(
    name=&#34;TrafficLightDetection&#34;, # This needs to match the folder name under plugins (this would mean plugins\Plugin\main.py)
    description=&#34;Detects traffic lights with vision.&#34;,
    version=&#34;0.4&#34;,
    author=&#34;Glas42, Tumppi066&#34;,
    url=&#34;https://github.com/Glas42/Euro-Truck-Simulator-2-Lane-Assist&#34;,
    type=&#34;dynamic&#34;, # = Panel
    dynamicOrder=&#34;before lane detection&#34; # Will run the plugin before anything else in the mainloop (data will be empty)
)

import tkinter as tk
from tkinter import ttk
import src.helpers as helpers
import src.mainUI as mainUI
import src.variables as variables
import src.settings as settings
from src.translator import Translate
from tkinter import messagebox
import os


import cv2
import numpy as np
import pyautogui
import ctypes
import math

screen_width, screen_height = pyautogui.size()

coordinates = []
trafficlights = []

lower_red = np.array([200, 0, 0])
upper_red = np.array([255, 110, 110])
lower_green = np.array([0, 200, 0])
upper_green = np.array([150, 255, 230])
lower_yellow = np.array([200, 170, 50])
upper_yellow = np.array([255, 240, 170])

yolo_model_loaded = False

def UpdateSettings():
    global min_rect_size
    global max_rect_size
    global width_height_ratio
    global circlepercent
    global maxcircleoffset
    global circleplusoffset
    global circleminusoffset
    global finalwindow
    global grayscalewindow
    global redyellowgreenwindow
    global anywindowopen
    global automaticwindowsize
    global detectyellowlight
    global performancemode
    global advancedmode
    global windowscale
    global usefullframe
    global yolo_detection
    global yolo_showunconfirmed
    global yolo_model_loaded
    global yolo_model
    global coordinates
    global trafficlights
    global windowwidth
    global windowheight
    global reset_window
    global x1
    global y1
    global x2
    global y2

    global rectsizefilter
    global widthheightratiofilter
    global pixelpercentagefilter
    global otherlightsofffilter
    global urr
    global urg
    global urb
    global lrr
    global lrg
    global lrb
    global uyr
    global uyg
    global uyb
    global lyr
    global lyg
    global lyb
    global ugr
    global ugg
    global ugb
    global lgr
    global lgg
    global lgb
    global lower_red_advanced
    global upper_red_advanced
    global lower_green_advanced
    global upper_green_advanced
    global lower_yellow_advanced
    global upper_yellow_advanced
    
    finalwindow = settings.GetSettings(&#34;TrafficLightDetection&#34;, &#34;finalwindow&#34;, True)
    grayscalewindow = settings.GetSettings(&#34;TrafficLightDetection&#34;, &#34;grayscalewindow&#34;, False)
    redyellowgreenwindow = settings.GetSettings(&#34;TrafficLightDetection&#34;, &#34;redyellowgreenwindow&#34;, False)
    automaticwindowsize = settings.GetSettings(&#34;TrafficLightDetection&#34;, &#34;automaticwindowsize&#34;, True)
    detectyellowlight = settings.GetSettings(&#34;TrafficLightDetection&#34;, &#34;detectyellowlight&#34;, False)
    performancemode = settings.GetSettings(&#34;TrafficLightDetection&#34;, &#34;performancemode&#34;, True)
    advancedmode = settings.GetSettings(&#34;TrafficLightDetection&#34;, &#34;advancedmode&#34;, False)
    usefullframe = settings.GetSettings(&#34;TrafficLightDetection&#34;, &#34;usefullframe&#34;, True)
    windowscale = float(settings.GetSettings(&#34;TrafficLightDetection&#34;, &#34;scale&#34;, 0.5))
    x1 = settings.GetSettings(&#34;TrafficLightDetection&#34;, &#34;x1ofsc&#34;, 0)
    y1 = settings.GetSettings(&#34;TrafficLightDetection&#34;, &#34;y1ofsc&#34;, 0)
    x2 = settings.GetSettings(&#34;TrafficLightDetection&#34;, &#34;x2ofsc&#34;, screen_width-1)
    y2 = settings.GetSettings(&#34;TrafficLightDetection&#34;, &#34;y2ofsc&#34;, round(screen_height/1.5)-1)

    rectsizefilter = settings.GetSettings(&#34;TrafficLightDetection&#34;, &#34;rectsizefilter&#34;, True)
    widthheightratiofilter = settings.GetSettings(&#34;TrafficLightDetection&#34;, &#34;widthheightratiofilter&#34;, True)
    pixelpercentagefilter = settings.GetSettings(&#34;TrafficLightDetection&#34;, &#34;pixelpercentagefilter&#34;, True)
    otherlightsofffilter = settings.GetSettings(&#34;TrafficLightDetection&#34;, &#34;otherlightsofffilter&#34;, True)

    yolo_detection = settings.GetSettings(&#34;TrafficLightDetection&#34;, &#34;yolo_detection&#34;, True)
    yolo_showunconfirmed = settings.GetSettings(&#34;TrafficLightDetection&#34;, &#34;yolo_showunconfirmed&#34;, True)

    coordinates = []
    trafficlights = []

    if automaticwindowsize == True:
        if usefullframe == False:
            windowwidth = x2-x1
            windowheight = y2-y1
        else:
            windowwidth = screen_width
            windowheight = round(screen_height/1.5)
    else:
        windowwidth = settings.GetSettings(&#34;TrafficLightDetection&#34;, &#34;outputwindowwidth&#34;, round(screen_width/2))
        windowheight = settings.GetSettings(&#34;TrafficLightDetection&#34;, &#34;outputwindowheight&#34;, round(screen_height/3))
    
    reset_window = True

    if advancedmode == False:
        min_rect_size = screen_width / 240
        max_rect_size = screen_width / 10
    else:
        min_rect_size = settings.GetSettings(&#34;TrafficLightDetection&#34;, &#34;minrectsize&#34;, round(screen_width / 240))
        max_rect_size = settings.GetSettings(&#34;TrafficLightDetection&#34;, &#34;maxrectsize&#34;, round(screen_width / 10))

    width_height_ratio = 0.2
    circlepercent = 0.785
    maxcircleoffset = 0.15
    circleplusoffset = circlepercent + maxcircleoffset
    circleminusoffset = circlepercent - maxcircleoffset

    if min_rect_size &lt; 8:
        min_rect_size = 8

    if ((finalwindow + grayscalewindow + redyellowgreenwindow) &gt; 0):
        anywindowopen = True
    else:
        anywindowopen = False

    if x2-x1-1 &lt; 0:
        print(&#34;Your Screen Capture Coordinates are invalid because the right X is to the left of the left X (message from TrafficLightDetection)&#34;)
        messagebox.showwarning(title=&#34;TrafficLightDetection&#34;, message=&#34;Your Screen Capture Coordinates are invalid because the right X is to the left of the left X (message from TrafficLightDetection)&#34;)
    if y2-y1-1 &lt; 0:
        print(&#34;Your Screen Capture Coordinates are invalid because the bottom Y is above the top Y (message from TrafficLightDetection)&#34;)
        messagebox.showwarning(title=&#34;TrafficLightDetection&#34;, message=&#34;Your Screen Capture Coordinates are invalid because the bottom Y is above the top Y (message from TrafficLightDetection)&#34;)
    
    urr = settings.GetSettings(&#34;TrafficLightDetection&#34;, &#34;upperred_r&#34;)
    if urr == None or not isinstance(urr, int) or not (0 &lt;= urr &lt;= 255):
        settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;upperred_r&#34;, 255)
        urr = 255
    urg = settings.GetSettings(&#34;TrafficLightDetection&#34;, &#34;upperred_g&#34;)
    if urg == None or not isinstance(urg, int) or not (0 &lt;= urg &lt;= 255):
        settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;upperred_g&#34;, 110)
        urg = 110
    urb = settings.GetSettings(&#34;TrafficLightDetection&#34;, &#34;upperred_b&#34;)
    if urb == None or not isinstance(urb, int) or not (0 &lt;= urb &lt;= 255):
        settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;upperred_b&#34;, 110)
        urb = 110
    lrr = settings.GetSettings(&#34;TrafficLightDetection&#34;, &#34;lowerred_r&#34;)
    if lrr == None or not isinstance(lrr, int) or not (0 &lt;= lrr &lt;= 255):
        settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;lowerred_r&#34;, 200)
        lrr = 200
    lrg = settings.GetSettings(&#34;TrafficLightDetection&#34;, &#34;lowerred_g&#34;)
    if lrg == None or not isinstance(lrg, int) or not (0 &lt;= lrg &lt;= 255):
        settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;lowerred_g&#34;, 0)
        lrg = 0
    lrb = settings.GetSettings(&#34;TrafficLightDetection&#34;, &#34;lowerred_b&#34;)
    if lrb == None or not isinstance(lrb, int) or not (0 &lt;= lrb &lt;= 255):
        settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;lowerred_b&#34;, 0)
        lrb = 0
    uyr = settings.GetSettings(&#34;TrafficLightDetection&#34;, &#34;upperyellow_r&#34;)
    if uyr == None or not isinstance(uyr, int) or not (0 &lt;= uyr &lt;= 255):
        settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;upperyellow_r&#34;, 255)
        uyr = 255
    uyg = settings.GetSettings(&#34;TrafficLightDetection&#34;, &#34;upperyellow_g&#34;)
    if uyg == None or not isinstance(uyg, int) or not (0 &lt;= uyg &lt;= 255):
        settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;upperyellow_g&#34;, 240)
        uyg = 240
    uyb = settings.GetSettings(&#34;TrafficLightDetection&#34;, &#34;upperyellow_b&#34;)
    if uyb == None or not isinstance(uyb, int) or not (0 &lt;= uyb &lt;= 255):
        settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;upperyellow_b&#34;, 170)
        uyb = 170
    lyr = settings.GetSettings(&#34;TrafficLightDetection&#34;, &#34;loweryellow_r&#34;)
    if lyr == None or not isinstance(lyr, int) or not (0 &lt;= lyr &lt;= 255):
        settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;loweryellow_r&#34;, 200)
        lyr = 200
    lyg = settings.GetSettings(&#34;TrafficLightDetection&#34;, &#34;loweryellow_g&#34;)
    if lyg == None or not isinstance(lyg, int) or not (0 &lt;= lyg &lt;= 255):
        settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;loweryellow_g&#34;, 170)
        lyg = 170
    lyb = settings.GetSettings(&#34;TrafficLightDetection&#34;, &#34;loweryellow_b&#34;)
    if lyb == None or not isinstance(lyb, int) or not (0 &lt;= lyb &lt;= 255):
        settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;loweryellow_b&#34;, 50)
        lyb = 50
    ugr = settings.GetSettings(&#34;TrafficLightDetection&#34;, &#34;uppergreen_r&#34;)
    if ugr == None or not isinstance(ugr, int) or not (0 &lt;= ugr &lt;= 255):
        settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;uppergreen_r&#34;, 150)
        ugr = 150
    ugg = settings.GetSettings(&#34;TrafficLightDetection&#34;, &#34;uppergreen_g&#34;)
    if ugg == None or not isinstance(ugg, int) or not (0 &lt;= ugg &lt;= 255):
        settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;uppergreen_g&#34;, 255)
        ugg = 255
    ugb = settings.GetSettings(&#34;TrafficLightDetection&#34;, &#34;uppergreen_b&#34;)
    if ugb == None or not isinstance(ugb, int) or not (0 &lt;= ugb &lt;= 255):
        settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;uppergreen_b&#34;, 230)
        ugb = 230
    lgr = settings.GetSettings(&#34;TrafficLightDetection&#34;, &#34;lowergreen_r&#34;)
    if lgr == None or not isinstance(lgr, int) or not (0 &lt;= lgr &lt;= 255):
        settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;lowergreen_r&#34;, 0)
        lgr = 0
    lgg = settings.GetSettings(&#34;TrafficLightDetection&#34;, &#34;lowergreen_g&#34;)
    if lgg == None or not isinstance(lgg, int) or not (0 &lt;= lgg &lt;= 255):
        settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;lowergreen_g&#34;, 200)
        lgg = 200
    lgb = settings.GetSettings(&#34;TrafficLightDetection&#34;, &#34;lowergreen_b&#34;)
    if lgb == None or not isinstance(lgb, int) or not (0 &lt;= lgb &lt;= 255):
        settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;lowergreen_b&#34;, 0)
        lgb = 0

    upper_red_advanced = np.array([urr, urg, urb])
    lower_red_advanced = np.array([lrr, lrg, lrb])
    upper_yellow_advanced = np.array([uyr, uyg, uyb])
    lower_yellow_advanced = np.array([lyr, lyg, lyb])
    upper_green_advanced = np.array([ugr, ugg, ugb])
    lower_green_advanced = np.array([lgr, lgg, lgb])
UpdateSettings()
    
def loadYOLO():
    global yolo_model_loaded
    global yolo_model
    global yolo_detection
    global yolo_showunconfirmed
    global yolo_model_str
    
    yolo_detection = settings.GetSettings(&#34;TrafficLightDetection&#34;, &#34;yolo_detection&#34;, True)
    yolo_showunconfirmed = settings.GetSettings(&#34;TrafficLightDetection&#34;, &#34;yolo_showunconfirmed&#34;, True)
    yolo_model_str = settings.GetSettings(&#34;TrafficLightDetection&#34;, &#34;yolo_model&#34;, &#34;yolov5n&#34;) # &#39;yolov5n&#39;, &#39;yolov5s&#39;, &#39;yolov5m&#39;, &#39;yolov5l&#39;, &#39;yolov5x&#39;
    if yolo_model_loaded == False:
        print(&#34;\033[92m&#34; + f&#34;Loading the {yolo_model_str} model...&#34; + &#34;\033[0m&#34;)
        try:
            import torch
            torch.hub.set_dir(f&#34;{variables.PATH}plugins\\TrafficLightDetection\\YoloFiles&#34;)
            yolo_model = torch.hub.load(&#34;ultralytics/yolov5&#34;, yolo_model_str)
            print(&#34;\033[92m&#34; + f&#34;Successfully loaded the {yolo_model_str} model!&#34; + &#34;\033[0m&#34;)
        except Exception as e:
            print(&#34;\033[91m&#34; + f&#34;Failed to load the {yolo_model_str} model: &#34; + &#34;\033[0m&#34; + str(e))
        yolo_model_loaded = True

def yolo_detection_function(yolo_detection_frame, x, y, w, h):
    trafficlight = False
    if yolo_model is None or yolo_model_loaded == False:
        loadYOLO()
    results = yolo_model(yolo_detection_frame)
    boxes = results.pandas().xyxy[0]
    for _, box in boxes.iterrows():
        if box[&#39;name&#39;] in [&#39;traffic light&#39;]:
            if (int(box[&#39;xmin&#39;]) &lt; round(yolo_detection_frame.shape[1] / 2) &lt; int(box[&#39;xmax&#39;])) and (int(box[&#39;ymin&#39;]) &lt; round(yolo_detection_frame.shape[0] / 2) &lt; int(box[&#39;ymax&#39;])):
                trafficlight = True
    return trafficlight


# The main file runs the &#34;plugin&#34; function each time the plugin is called
# The data variable contains the data from the mainloop, plugins can freely add and modify data as needed
# The data from the last frame is contained under data[&#34;last&#34;]
def plugin(data):
    global coordinates
    global trafficlights
    global reset_window
    
    try:
        frameFull = data[&#34;frameFull&#34;]
        if usefullframe == False and x2-x1 &gt; 0 and y2-y1 &gt; 0:
            frame = frameFull[y1:y1+(y2-y1), x1:x1+(x2-x1)]
        else: 
            frame = frameFull[0:round(screen_height/1.5), 0:screen_width] 
    except:
        return data
    
    if frame is None: return data
    rgb_frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)

    # ALL CASES:

    # True: --- False: advancedmode, performancemode, detectyellowlight
    # True: detectyellowlight --- False: advancedmode, performancemode
    # True: performancemode --- False: advancedmode
    # True: --- False: advancedmode, performancemode, detectyellowlight
    # True: detectyellowlight --- False: advancedmode, performancemode
    # True: performancemode --- False: advancedmode
    # True: advancedmode --- False: performancemode, detectyellowlight
    # True: advancedmode, detectyellowlight --- False: performancemode
    # True: advancedmode, performancemode --- False: 
    # True: advancedmode --- False: performancemode, detectyellowlight
    # True: advancedmode, detectyellowlight --- False: performancemode
    # True: advancedmode, performancemode --- False: 

    last_coordinates = coordinates.copy()
    coordinates = []
    if advancedmode == False:
        if performancemode == False:
            if detectyellowlight == False:
                # True: --- False: advancedmode, performancemode, detectyellowlight
                mask_red = cv2.inRange(rgb_frame, lower_red, upper_red)
                mask_green = cv2.inRange(rgb_frame, lower_green, upper_green)
                filtered_frame_red_yellow_green = cv2.bitwise_or(cv2.bitwise_and(frame, frame, mask=mask_red), cv2.bitwise_and(frame, frame, mask=mask_green))
                filtered_frame_bw = cv2.cvtColor(filtered_frame_red_yellow_green, cv2.COLOR_BGR2GRAY)
                final_frame = frame
                contours, _ = cv2.findContours(cv2.cvtColor(filtered_frame_red_yellow_green, cv2.COLOR_BGR2GRAY), cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
                for contour in contours:
                    x, y, w, h = cv2.boundingRect(contour)
                    if min_rect_size &lt; w and max_rect_size &gt; w and min_rect_size &lt; h and max_rect_size &gt; h:
                        if w / h - 1 &lt; width_height_ratio and w / h - 1 &gt; -width_height_ratio:
                            red_pixel_count = cv2.countNonZero(mask_red[y:y+h, x:x+w])
                            green_pixel_count = cv2.countNonZero(mask_green[y:y+h, x:x+w])
                            total_pixels = w * h
                            red_ratio = red_pixel_count / total_pixels
                            green_ratio = green_pixel_count / total_pixels
                            if green_ratio &lt; circleplusoffset and green_ratio &gt; circleminusoffset and red_ratio &lt; 0.1 or red_ratio &lt; circleplusoffset and red_ratio &gt; circleminusoffset and green_ratio &lt; 0.1:
                                if red_ratio &gt; green_ratio:
                                    colorstr = &#34;Red&#34;
                                    yoffset1 = y+h*2
                                    centerx = round(x + w / 2)
                                    centery1 = round(y + h / 2)+h
                                    centery2 = round(y + h / 2)+h*2
                                elif green_ratio &gt; red_ratio:
                                    colorstr = &#34;Green&#34;
                                    yoffset1 = y-h
                                    centerx = round(x + w / 2)
                                    centery1 = round(y + h / 2)-h
                                    centery2 = round(y + h / 2)-h*2
                                else:
                                    colorstr = &#34;Red&#34;
                                    yoffset1 = y+h*2
                                    centerx = round(x + w / 2)
                                    centery1 = round(y + h / 2)+h
                                    centery2 = round(y + h / 2)+h*2
                                try:
                                    centery1_color = rgb_frame[centery1, centerx]
                                except:
                                    centery1_color = (0,0,0)
                                try:
                                    centery2_color = rgb_frame[centery2, centerx]
                                except:
                                    centery2_color = (0,0,0)
                                r_centery1, g_centery1, b_centery1 = centery1_color
                                r_centery2, g_centery2, b_centery2 = centery2_color
                                if r_centery1 &lt; 100 and g_centery1 &lt; 100 and b_centery1 &lt; 100 and r_centery2 &lt; 100 and g_centery2 &lt; 100 and b_centery2 &lt; 100:
                                    coordinates.append((round(x+w/2),round(yoffset1-h/2),w,h,colorstr))

            else:
                # True: detectyellowlight --- False: advancedmode, performancemode
                mask_red = cv2.inRange(rgb_frame, lower_red, upper_red)
                mask_green = cv2.inRange(rgb_frame, lower_green, upper_green)
                mask_yellow = cv2.inRange(rgb_frame, lower_yellow, upper_yellow)
                combined_mask = cv2.bitwise_or(mask_red, cv2.bitwise_or(mask_green, mask_yellow))
                filtered_frame_red_yellow_green = cv2.bitwise_and(frame, frame, mask=combined_mask)
                filtered_frame_bw = cv2.cvtColor(filtered_frame_red_yellow_green, cv2.COLOR_BGR2GRAY)
                final_frame = frame
                contours, _ = cv2.findContours(cv2.cvtColor(filtered_frame_red_yellow_green, cv2.COLOR_BGR2GRAY), cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
                for contour in contours:
                    x, y, w, h = cv2.boundingRect(contour)
                    if min_rect_size &lt; w and max_rect_size &gt; w and min_rect_size &lt; h and max_rect_size &gt; h:
                        if w / h - 1 &lt; width_height_ratio and w / h - 1 &gt; -width_height_ratio:
                            red_pixel_count = cv2.countNonZero(mask_red[y:y+h, x:x+w])
                            green_pixel_count = cv2.countNonZero(mask_green[y:y+h, x:x+w])
                            yellow_pixel_count = cv2.countNonZero(mask_yellow[y:y+h, x:x+w])
                            total_pixels = w * h
                            red_ratio = red_pixel_count / total_pixels
                            green_ratio = green_pixel_count / total_pixels
                            yellow_ratio = yellow_pixel_count / total_pixels
                            if (green_ratio &lt; circleplusoffset and green_ratio &gt; circleminusoffset and red_ratio &lt; 0.1 and yellow_ratio &lt; 0.1 or 
                                red_ratio &lt; circleplusoffset and red_ratio &gt; circleminusoffset and green_ratio &lt; 0.1 and yellow_ratio &lt; 0.1 or 
                                yellow_ratio &lt; circleplusoffset and yellow_ratio &gt; circleminusoffset and green_ratio &lt; 0.1 and red_ratio &lt; 0.1):
                                if red_ratio &gt; green_ratio and red_ratio &gt; yellow_ratio:
                                    colorstr = &#34;Red&#34;
                                    yoffset1 = y+h*2
                                    centerx = round(x + w / 2)
                                    centery1 = round(y + h / 2)+h
                                    centery2 = round(y + h / 2)+h*2
                                elif yellow_ratio &gt; red_ratio and yellow_ratio &gt; green_ratio:
                                    colorstr = &#34;Yellow&#34;
                                    yoffset1 = y+h
                                    centerx = round(x + w / 2)
                                    centery1 = round(y + h / 2)-h
                                    centery2 = round(y + h / 2)+h
                                elif green_ratio &gt; red_ratio and green_ratio &gt; yellow_ratio:
                                    colorstr = &#34;Green&#34;
                                    yoffset1 = y-h
                                    centerx = round(x + w / 2)
                                    centery1 = round(y + h / 2)-h
                                    centery2 = round(y + h / 2)-h*2
                                else:
                                    colorstr = &#34;Red&#34;
                                    yoffset1 = y+h*2
                                    centerx = round(x + w / 2)
                                    centery1 = round(y + h / 2)+h
                                    centery2 = round(y + h / 2)+h*2
                                try:
                                    centery1_color = rgb_frame[centery1, centerx]
                                except:
                                    centery1_color = (0,0,0)
                                try:
                                    centery2_color = rgb_frame[centery2, centerx]
                                except:
                                    centery2_color = (0,0,0)
                                r_centery1, g_centery1, b_centery1 = centery1_color
                                r_centery2, g_centery2, b_centery2 = centery2_color
                                if r_centery1 &lt; 100 and g_centery1 &lt; 100 and b_centery1 &lt; 100 and r_centery2 &lt; 100 and g_centery2 &lt; 100 and b_centery2 &lt; 100:
                                    coordinates.append((round(x+w/2),round(yoffset1-h/2),w,h,colorstr))
                
        else:
            # True: performancemode --- False: advancedmode
            mask_red = cv2.inRange(rgb_frame, lower_red, upper_red)
            filtered_frame_red_yellow_green = cv2.bitwise_and(frame, frame, mask=mask_red)
            filtered_frame_bw = mask_red.copy()
            final_frame = frame
            contours, _ = cv2.findContours(mask_red, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
            for contour in contours:
                x, y, w, h = cv2.boundingRect(contour)
                if min_rect_size &lt; w and max_rect_size &gt; w and min_rect_size &lt; h and max_rect_size &gt; h:
                    if w / h - 1 &lt; width_height_ratio and w / h - 1 &gt; -width_height_ratio:
                        red_pixel_count = cv2.countNonZero(mask_red[y:y+h, x:x+w])
                        total_pixels = w * h
                        red_ratio = red_pixel_count / total_pixels
                        if red_ratio &lt; circleplusoffset and red_ratio &gt; circleminusoffset:
                            colorstr = &#34;Red&#34;
                            yoffset1 = y+h*2
                            centerx = round(x + w / 2)
                            centery1 = round(y + h / 2)+h
                            centery2 = round(y + h / 2)+h*2
                            try:
                                centery1_color = rgb_frame[centery1, centerx]
                            except:
                                centery1_color = (0,0,0)
                            try:
                                centery2_color = rgb_frame[centery2, centerx]
                            except:
                                centery2_color = (0,0,0)
                            r_centery1, g_centery1, b_centery1 = centery1_color
                            r_centery2, g_centery2, b_centery2 = centery2_color
                            if r_centery1 &lt; 100 and g_centery1 &lt; 100 and b_centery1 &lt; 100 and r_centery2 &lt; 100 and g_centery2 &lt; 100 and b_centery2 &lt; 100:
                                coordinates.append((round(x+w/2),round(yoffset1-h/2),w,h,colorstr))

    else:

        if performancemode == False:
            if detectyellowlight == False:
                # True: advancedmode --- False: performancemode, detectyellowlight
                mask_red = cv2.inRange(rgb_frame, lower_red_advanced, upper_red_advanced)
                mask_green = cv2.inRange(rgb_frame, lower_green_advanced, upper_green_advanced)
                filtered_frame_red_yellow_green = cv2.bitwise_or(cv2.bitwise_and(frame, frame, mask=mask_red), cv2.bitwise_and(frame, frame, mask=mask_green))
                filtered_frame_bw = cv2.cvtColor(filtered_frame_red_yellow_green, cv2.COLOR_BGR2GRAY)
                final_frame = frame
                contours, _ = cv2.findContours(cv2.cvtColor(filtered_frame_red_yellow_green, cv2.COLOR_BGR2GRAY), cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
                for contour in contours:
                    x, y, w, h = cv2.boundingRect(contour)
                    istrue = False
                    if rectsizefilter == True:
                        if min_rect_size &lt; w and max_rect_size &gt; w and min_rect_size &lt; h and max_rect_size &gt; h:
                            istrue = True
                    else:
                        istrue = True
                    if istrue == True:
                        istrue = False
                        if widthheightratiofilter == True:
                            if w / h - 1 &lt; width_height_ratio and w / h - 1 &gt; -width_height_ratio:
                                istrue = True
                        else:
                            istrue = True
                        if istrue == True:
                            red_pixel_count = cv2.countNonZero(mask_red[y:y+h, x:x+w])
                            green_pixel_count = cv2.countNonZero(mask_green[y:y+h, x:x+w])
                            total_pixels = w * h
                            red_ratio = red_pixel_count / total_pixels
                            green_ratio = green_pixel_count / total_pixels
                            istrue = False
                            if pixelpercentagefilter == True:
                                if green_ratio &lt; circleplusoffset and green_ratio &gt; circleminusoffset and red_ratio &lt; 0.1 or red_ratio &lt; circleplusoffset and red_ratio &gt; circleminusoffset and green_ratio &lt; 0.1:
                                    istrue = True
                            else:
                                istrue = True
                            if istrue == True:
                                if red_ratio &gt; green_ratio:
                                    colorstr = &#34;Red&#34;
                                    yoffset1 = y+h*2
                                    centerx = round(x + w / 2)
                                    centery1 = round(y + h / 2)+h
                                    centery2 = round(y + h / 2)+h*2
                                elif green_ratio &gt; red_ratio:
                                    colorstr = &#34;Green&#34;
                                    yoffset1 = y-h
                                    centerx = round(x + w / 2)
                                    centery1 = round(y + h / 2)-h
                                    centery2 = round(y + h / 2)-h*2
                                else:
                                    colorstr = &#34;Red&#34;
                                    yoffset1 = y+h*2
                                    centerx = round(x + w / 2)
                                    centery1 = round(y + h / 2)+h
                                    centery2 = round(y + h / 2)+h*2
                                try:
                                    centery1_color = rgb_frame[centery1, centerx]
                                except:
                                    centery1_color = (0,0,0)
                                try:
                                    centery2_color = rgb_frame[centery2, centerx]
                                except:
                                    centery2_color = (0,0,0)
                                r_centery1, g_centery1, b_centery1 = centery1_color
                                r_centery2, g_centery2, b_centery2 = centery2_color
                                istrue = False
                                if otherlightsofffilter == True:
                                    if r_centery1 &lt; 100 and g_centery1 &lt; 100 and b_centery1 &lt; 100 and r_centery2 &lt; 100 and g_centery2 &lt; 100 and b_centery2 &lt; 100:
                                        istrue = True
                                else:
                                    istrue = True
                                if istrue == True:
                                    coordinates.append((round(x+w/2),round(yoffset1-h/2),w,h,colorstr))

            else:
                # True: advancedmode, detectyellowlight --- False: performancemode
                mask_red = cv2.inRange(rgb_frame, lower_red_advanced, upper_red_advanced)
                mask_green = cv2.inRange(rgb_frame, lower_green_advanced, upper_green_advanced)
                mask_yellow = cv2.inRange(rgb_frame, lower_yellow_advanced, upper_yellow_advanced)
                combined_mask = cv2.bitwise_or(mask_red, cv2.bitwise_or(mask_green, mask_yellow))
                filtered_frame_red_yellow_green = cv2.bitwise_and(frame, frame, mask=combined_mask)
                filtered_frame_bw = cv2.cvtColor(filtered_frame_red_yellow_green, cv2.COLOR_BGR2GRAY)
                final_frame = frame
                contours, _ = cv2.findContours(cv2.cvtColor(filtered_frame_red_yellow_green, cv2.COLOR_BGR2GRAY), cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
                for contour in contours:
                    x, y, w, h = cv2.boundingRect(contour)
                    istrue = False
                    if rectsizefilter == True:
                        if min_rect_size &lt; w and max_rect_size &gt; w and min_rect_size &lt; h and max_rect_size &gt; h:
                            istrue = True
                    else:
                        istrue = True
                    if istrue == True:
                        istrue = False
                        if widthheightratiofilter == True:
                            if w / h - 1 &lt; width_height_ratio and w / h - 1 &gt; -width_height_ratio:
                                istrue = True
                        else:
                            istrue = True
                        if istrue == True:
                            red_pixel_count = cv2.countNonZero(mask_red[y:y+h, x:x+w])
                            green_pixel_count = cv2.countNonZero(mask_green[y:y+h, x:x+w])
                            yellow_pixel_count = cv2.countNonZero(mask_yellow[y:y+h, x:x+w])
                            total_pixels = w * h
                            red_ratio = red_pixel_count / total_pixels
                            green_ratio = green_pixel_count / total_pixels
                            yellow_ratio = yellow_pixel_count / total_pixels
                            istrue = False
                            if pixelpercentagefilter == True:
                                if (green_ratio &lt; circleplusoffset and green_ratio &gt; circleminusoffset and red_ratio &lt; 0.1 and yellow_ratio &lt; 0.1 or 
                                    red_ratio &lt; circleplusoffset and red_ratio &gt; circleminusoffset and green_ratio &lt; 0.1 and yellow_ratio &lt; 0.1 or 
                                    yellow_ratio &lt; circleplusoffset and yellow_ratio &gt; circleminusoffset and green_ratio &lt; 0.1 and red_ratio &lt; 0.1):
                                    istrue = True
                            else:
                                istrue = True
                            if istrue == True:
                                if red_ratio &gt; green_ratio and red_ratio &gt; yellow_ratio:
                                    colorstr = &#34;Red&#34;
                                    yoffset1 = y+h*2
                                    centerx = round(x + w / 2)
                                    centery1 = round(y + h / 2)+h
                                    centery2 = round(y + h / 2)+h*2
                                elif yellow_ratio &gt; red_ratio and yellow_ratio &gt; green_ratio:
                                    colorstr = &#34;Yellow&#34;
                                    yoffset1 = y+h
                                    centerx = round(x + w / 2)
                                    centery1 = round(y + h / 2)-h
                                    centery2 = round(y + h / 2)+h
                                elif green_ratio &gt; red_ratio and green_ratio &gt; yellow_ratio:
                                    colorstr = &#34;Green&#34;
                                    yoffset1 = y-h
                                    centerx = round(x + w / 2)
                                    centery1 = round(y + h / 2)-h
                                    centery2 = round(y + h / 2)-h*2
                                else:
                                    colorstr = &#34;Red&#34;
                                    yoffset1 = y+h*2
                                    centerx = round(x + w / 2)
                                    centery1 = round(y + h / 2)+h
                                    centery2 = round(y + h / 2)+h*2
                                try:
                                    centery1_color = rgb_frame[centery1, centerx]
                                except:
                                    centery1_color = (0,0,0)
                                try:
                                    centery2_color = rgb_frame[centery2, centerx]
                                except:
                                    centery2_color = (0,0,0)
                                r_centery1, g_centery1, b_centery1 = centery1_color
                                r_centery2, g_centery2, b_centery2 = centery2_color
                                istrue = False
                                if otherlightsofffilter == True:
                                    if r_centery1 &lt; 100 and g_centery1 &lt; 100 and b_centery1 &lt; 100 and r_centery2 &lt; 100 and g_centery2 &lt; 100 and b_centery2 &lt; 100:
                                        istrue = True
                                else:
                                    istrue = True
                                if istrue == True:
                                    coordinates.append((round(x+w/2),round(yoffset1-h/2),w,h,colorstr))
                    
        else:
            # True: advancedmode, performancemode --- False:     
            mask_red = cv2.inRange(rgb_frame, lower_red_advanced, upper_red_advanced)
            filtered_frame_red_yellow_green = cv2.bitwise_and(frame, frame, mask=mask_red)
            filtered_frame_bw = mask_red.copy()
            final_frame = frame
            contours, _ = cv2.findContours(mask_red, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
            for contour in contours:
                x, y, w, h = cv2.boundingRect(contour)
                istrue = False
                if rectsizefilter == True:
                    if min_rect_size &lt; w and max_rect_size &gt; w and min_rect_size &lt; h and max_rect_size &gt; h:
                        istrue = True
                else:
                    istrue = True
                if istrue == True:
                    istrue = False
                    if widthheightratiofilter == True:
                        if w / h - 1 &lt; width_height_ratio and w / h - 1 &gt; -width_height_ratio:
                            istrue = True
                    else:
                        istrue = True
                    if istrue == True:
                        red_pixel_count = cv2.countNonZero(mask_red[y:y+h, x:x+w])
                        total_pixels = w * h
                        red_ratio = red_pixel_count / total_pixels
                        istrue = False
                        if pixelpercentagefilter == True:
                            if red_ratio &lt; circleplusoffset and red_ratio &gt; circleminusoffset:
                                istrue = True
                        else:
                            istrue = True
                        if istrue == True:
                            colorstr = &#34;Red&#34;
                            yoffset1 = y+h*2
                            centerx = round(x + w / 2)
                            centery1 = round(y + h / 2)+h
                            centery2 = round(y + h / 2)+h*2
                            try:
                                centery1_color = rgb_frame[centery1, centerx]
                            except:
                                centery1_color = (0,0,0)
                            try:
                                centery2_color = rgb_frame[centery2, centerx]
                            except:
                                centery2_color = (0,0,0)
                            r_centery1, g_centery1, b_centery1 = centery1_color
                            r_centery2, g_centery2, b_centery2 = centery2_color
                            istrue = False
                            if otherlightsofffilter == True:
                                if r_centery1 &lt; 100 and g_centery1 &lt; 100 and b_centery1 &lt; 100 and r_centery2 &lt; 100 and g_centery2 &lt; 100 and b_centery2 &lt; 100:
                                    istrue = True
                            else:
                                istrue = True
                            if istrue == True:
                                coordinates.append((round(x+w/2),round(yoffset1-h/2),w,h,colorstr))

    if yolo_detection == True:
        try:
            # Tracking with IDs:

            def generate_new_id():
                used_ids = set(id for _, id, _ in trafficlights)
                new_id = 1
                while new_id in used_ids:
                    new_id += 1
                return new_id

            if last_coordinates:
                for i in range(len(last_coordinates)):
                    last_x, last_y, w, h, state = last_coordinates[i]
                    closest = screen_width
                    nearestpoint = None
                    exists_in_trafficlights = False
                    saved_id = None
                    saved_approved = None
                    for j in range(len(coordinates)):
                        x, y, w, h, state = coordinates[j]
                        distance = math.sqrt((x - last_x)**2 + (y - last_y)**2)
                        if distance &lt; closest:
                            closest = distance
                            nearestpoint = x, y, w, h, state

                    # Remove missing points from traffic lights and update list
                    if nearestpoint:
                        for k, (coord, id, approved) in enumerate(trafficlights):
                            if coord == last_coordinates[i]:
                                exists_in_trafficlights = True
                                saved_id = id
                                saved_approved = approved
                                del trafficlights[k]
                                break
                        if exists_in_trafficlights:
                            trafficlights.append((nearestpoint, saved_id, saved_approved))
                        else:
                            new_id = generate_new_id()
                            x, y, w, h, state = nearestpoint
                            x1_confirmation = round(x - w*6)
                            y1_confirmation = round(y - w*7)
                            x2_confirmation = round(x + w*6)
                            y2_confirmation = round(y + w*7)
                            if x1_confirmation &lt; 0:
                                x1_confirmation = 0
                            if y1_confirmation &lt; 0:
                                y1_confirmation = 0
                            if x2_confirmation &gt; screen_width - 1:
                                x2_confirmation = screen_width - 1
                            if y2_confirmation &gt; screen_height - 1:
                                y2_confirmation = screen_height - 1
                            if usefullframe == False and x2-x1 &gt; 0 and y2-y1 &gt; 0:
                                yolo_detection_frame = frameFull[y1+y1_confirmation:y1+y2_confirmation, x1+x1_confirmation:x1+x2_confirmation]
                            else:
                                yolo_detection_frame = frameFull[y1_confirmation:y2_confirmation, x1_confirmation:x2_confirmation]
                            approved = yolo_detection_function(yolo_detection_frame, x, y, w, h)
                            trafficlights.append((nearestpoint, new_id, approved))

                # Remove lost traffic lights based on distance traveled
                lost_trafficlights = len(last_coordinates) - len(coordinates)
                if lost_trafficlights &gt; 0:
                    max_distances = []
                    for i, ((x, y, w, h, state), _, _) in enumerate(trafficlights):
                        if i &lt; len(last_coordinates):
                            distance = math.sqrt((x - last_coordinates[i][0])**2 + (y - last_coordinates[i][1])**2)
                            max_distances.append((distance, i))
                    max_distances.sort(reverse=True)
                    for _ in range(lost_trafficlights):
                        if max_distances:
                            max_index = max_distances.pop(0)[1]
                            del trafficlights[max_index]

                # Filter to remove extra IDs
                if len(trafficlights) &gt; len(coordinates):
                    id_counts = {}
                    for _, id, _ in trafficlights:
                        id_counts[id] = id_counts.get(id, 0) + 1

                    for _ in range(len(trafficlights) - len(coordinates)):
                        max_index = None
                        max_count = 0
                        for i, (_, id, _) in enumerate(trafficlights):
                            if id_counts[id] &gt; max_count:
                                max_index = i
                                max_count = id_counts[id]

                        if max_index is not None:
                            del trafficlights[max_index]
                            id_counts[trafficlights[max_index][1]] -= 1

                
            if anywindowopen == True:
                for i in range(len(trafficlights)):
                    coord, id, approved = trafficlights[i]
                    x, y, w, h, state = coord
                    radius = round((w+h)/4)
                    thickness = round((w+h)/30)
                    if thickness &lt; 1:
                        thickness = 1
                    if approved == True:
                        if state == &#34;Red&#34;:
                            color = (0, 0, 255)
                            cv2.circle(final_frame, (x,y-h), radius, color, thickness)
                            cv2.circle(filtered_frame_bw, (x,y-h), radius, (255, 255, 255), thickness)
                            cv2.circle(filtered_frame_red_yellow_green, (x,y-h), radius,color, thickness)
                            cv2.rectangle(final_frame, (x-w, y-h*2), (x+w, y+h*2), color, radius)
                            cv2.rectangle(filtered_frame_red_yellow_green, (x-w, y-h*2), (x+w, y+h*2), color, radius)
                            if grayscalewindow == True:
                                cv2.rectangle(filtered_frame_bw, (x-round(w/2), y-round(h*1.5)), (x+round(w/2), y-round(h/2)), (150, 150, 150), thickness)
                            if redyellowgreenwindow == True:
                                cv2.rectangle(filtered_frame_red_yellow_green, (x-round(w/2), y-round(h*1.5)), (x+round(w/2), y-round(h/2)), (150, 150, 150), thickness)
                                cv2.rectangle(filtered_frame_red_yellow_green, (x-round(w/2), y-round(h/2)), (x+round(w/2), y+round(h/2)), (150, 150, 150), thickness)
                                cv2.rectangle(filtered_frame_red_yellow_green, (x-round(w/2), y+round(h/2)), (x+round(w/2), y+round(h*1.5)), (150, 150, 150), thickness)
                            if finalwindow == True:
                                cv2.rectangle(final_frame, (x-round(w/2), y-round(h*1.5)), (x+round(w/2), y-round(h/2)), (150, 150, 150), thickness)
                                cv2.rectangle(final_frame, (x-round(w/2), y-round(h/2)), (x+round(w/2), y+round(h/2)), (150, 150, 150), thickness)
                                cv2.rectangle(final_frame, (x-round(w/2), y+round(h/2)), (x+round(w/2), y+round(h*1.5)), (150, 150, 150), thickness)
                        if state == &#34;Yellow&#34;:
                            color = (0, 255, 255)
                            cv2.circle(final_frame, (x,y), radius, color, thickness)
                            cv2.circle(filtered_frame_bw, (x,y), radius, (255, 255, 255), thickness)
                            cv2.circle(filtered_frame_red_yellow_green, (x,y), radius,color, thickness)
                            cv2.rectangle(final_frame, (x-w, y-h*2), (x+w, y+h*2), color, radius)
                            cv2.rectangle(filtered_frame_red_yellow_green, (x-w, y-h*2), (x+w, y+h*2), color, radius)
                            if grayscalewindow == True:
                                cv2.rectangle(filtered_frame_bw, (x-round(w/2), y-round(h/2)), (x+round(w/2), y+round(h/2)), (150, 150, 150), thickness)
                            if redyellowgreenwindow == True:
                                cv2.rectangle(filtered_frame_red_yellow_green, (x-round(w/2), y-round(h*1.5)), (x+round(w/2), y-round(h/2)), (150, 150, 150), thickness)
                                cv2.rectangle(filtered_frame_red_yellow_green, (x-round(w/2), y-round(h/2)), (x+round(w/2), y+round(h/2)), (150, 150, 150), thickness)
                                cv2.rectangle(filtered_frame_red_yellow_green, (x-round(w/2), y+round(h/2)), (x+round(w/2), y+round(h*1.5)), (150, 150, 150), thickness)
                            if finalwindow == True:
                                cv2.rectangle(final_frame, (x-round(w/2), y-round(h*1.5)), (x+round(w/2), y-round(h/2)), (150, 150, 150), thickness)
                                cv2.rectangle(final_frame, (x-round(w/2), y-round(h/2)), (x+round(w/2), y+round(h/2)), (150, 150, 150), thickness)
                                cv2.rectangle(final_frame, (x-round(w/2), y+round(h/2)), (x+round(w/2), y+round(h*1.5)), (150, 150, 150), thickness)
                        if state == &#34;Green&#34;:
                            color = (0, 255, 0)
                            cv2.circle(final_frame, (x,y+h*2), radius, color, thickness)
                            cv2.circle(filtered_frame_bw, (x,y+h*2), radius, (255, 255, 255), thickness)
                            cv2.circle(filtered_frame_red_yellow_green, (x,y+h*2), radius,color, thickness)
                            cv2.rectangle(final_frame, (x-w, y-h), (x+w, y+h*3), color, radius)
                            cv2.rectangle(filtered_frame_red_yellow_green, (x-w, y-h), (x+w, y+h*3), color, radius)
                            if grayscalewindow == True:
                                cv2.rectangle(filtered_frame_bw, (x-round(w/2), y+round(h*1.5)), (x+round(w/2), y+round(h*2.5)), (150, 150, 150), thickness)
                            if redyellowgreenwindow == True:
                                cv2.rectangle(filtered_frame_red_yellow_green, (x-round(w/2), y-round(h/2)), (x+round(w/2), y+round(h/2)), (150, 150, 150), thickness)
                                cv2.rectangle(filtered_frame_red_yellow_green, (x-round(w/2), y+round(h/2)), (x+round(w/2), y+round(h*1.5)), (150, 150, 150), thickness)
                                cv2.rectangle(filtered_frame_red_yellow_green, (x-round(w/2), y+round(h*1.5)), (x+round(w/2), y+round(h*2.5)), (150, 150, 150), thickness)
                            if finalwindow == True:
                                cv2.rectangle(final_frame, (x-round(w/2), y-round(h/2)), (x+round(w/2), y+round(h/2)), (150, 150, 150), thickness)
                                cv2.rectangle(final_frame, (x-round(w/2), y+round(h/2)), (x+round(w/2), y+round(h*1.5)), (150, 150, 150), thickness)
                                cv2.rectangle(final_frame, (x-round(w/2), y+round(h*1.5)), (x+round(w/2), y+round(h*2.5)), (150, 150, 150), thickness)
                    elif approved == False and yolo_showunconfirmed == True:
                        if state == &#34;Red&#34;:
                            color = (150, 150, 150)
                            cv2.circle(final_frame, (x,y-h), radius, color, thickness)
                            cv2.circle(filtered_frame_bw, (x,y-h), radius, (255, 255, 255), thickness)
                            cv2.circle(filtered_frame_red_yellow_green, (x,y-h), radius,color, thickness)
                            cv2.rectangle(final_frame, (x-w, y-h*2), (x+w, y+h*2), color, radius)
                            cv2.rectangle(filtered_frame_red_yellow_green, (x-w, y-h*2), (x+w, y+h*2), color, radius)
                            if grayscalewindow == True:
                                cv2.rectangle(filtered_frame_bw, (x-round(w/2), y-round(h*1.5)), (x+round(w/2), y-round(h/2)), (150, 150, 150), thickness)
                            if redyellowgreenwindow == True:
                                cv2.rectangle(filtered_frame_red_yellow_green, (x-round(w/2), y-round(h*1.5)), (x+round(w/2), y-round(h/2)), (150, 150, 150), thickness)
                                cv2.rectangle(filtered_frame_red_yellow_green, (x-round(w/2), y-round(h/2)), (x+round(w/2), y+round(h/2)), (150, 150, 150), thickness)
                                cv2.rectangle(filtered_frame_red_yellow_green, (x-round(w/2), y+round(h/2)), (x+round(w/2), y+round(h*1.5)), (150, 150, 150), thickness)
                            if finalwindow == True:
                                cv2.rectangle(final_frame, (x-round(w/2), y-round(h*1.5)), (x+round(w/2), y-round(h/2)), (150, 150, 150), thickness)
                                cv2.rectangle(final_frame, (x-round(w/2), y-round(h/2)), (x+round(w/2), y+round(h/2)), (150, 150, 150), thickness)
                                cv2.rectangle(final_frame, (x-round(w/2), y+round(h/2)), (x+round(w/2), y+round(h*1.5)), (150, 150, 150), thickness)
                        if state == &#34;Yellow&#34;:
                            color = (150, 150, 150)
                            cv2.circle(final_frame, (x,y), radius, color, thickness)
                            cv2.circle(filtered_frame_bw, (x,y), radius, (255, 255, 255), thickness)
                            cv2.circle(filtered_frame_red_yellow_green, (x,y), radius,color, thickness)
                            cv2.rectangle(final_frame, (x-w, y-h*2), (x+w, y+h*2), color, radius)
                            cv2.rectangle(filtered_frame_red_yellow_green, (x-w, y-h*2), (x+w, y+h*2), color, radius)
                            if grayscalewindow == True:
                                cv2.rectangle(filtered_frame_bw, (x-round(w/2), y-round(h/2)), (x+round(w/2), y+round(h/2)), (150, 150, 150), thickness)
                            if redyellowgreenwindow == True:
                                cv2.rectangle(filtered_frame_red_yellow_green, (x-round(w/2), y-round(h*1.5)), (x+round(w/2), y-round(h/2)), (150, 150, 150), thickness)
                                cv2.rectangle(filtered_frame_red_yellow_green, (x-round(w/2), y-round(h/2)), (x+round(w/2), y+round(h/2)), (150, 150, 150), thickness)
                                cv2.rectangle(filtered_frame_red_yellow_green, (x-round(w/2), y+round(h/2)), (x+round(w/2), y+round(h*1.5)), (150, 150, 150), thickness)
                            if finalwindow == True:
                                cv2.rectangle(final_frame, (x-round(w/2), y-round(h*1.5)), (x+round(w/2), y-round(h/2)), (150, 150, 150), thickness)
                                cv2.rectangle(final_frame, (x-round(w/2), y-round(h/2)), (x+round(w/2), y+round(h/2)), (150, 150, 150), thickness)
                                cv2.rectangle(final_frame, (x-round(w/2), y+round(h/2)), (x+round(w/2), y+round(h*1.5)), (150, 150, 150), thickness)
                        if state == &#34;Green&#34;:
                            color = (150, 150, 150)
                            cv2.circle(final_frame, (x,y+h*2), radius, color, thickness)
                            cv2.circle(filtered_frame_bw, (x,y+h*2), radius, (255, 255, 255), thickness)
                            cv2.circle(filtered_frame_red_yellow_green, (x,y+h*2), radius,color, thickness)
                            cv2.rectangle(final_frame, (x-w, y-h), (x+w, y+h*3), color, radius)
                            cv2.rectangle(filtered_frame_red_yellow_green, (x-w, y-h), (x+w, y+h*3), color, radius)
                            if grayscalewindow == True:
                                cv2.rectangle(filtered_frame_bw, (x-round(w/2), y+round(h*1.5)), (x+round(w/2), y+round(h*2.5)), (150, 150, 150), thickness)
                            if redyellowgreenwindow == True:
                                cv2.rectangle(filtered_frame_red_yellow_green, (x-round(w/2), y-round(h/2)), (x+round(w/2), y+round(h/2)), (150, 150, 150), thickness)
                                cv2.rectangle(filtered_frame_red_yellow_green, (x-round(w/2), y+round(h/2)), (x+round(w/2), y+round(h*1.5)), (150, 150, 150), thickness)
                                cv2.rectangle(filtered_frame_red_yellow_green, (x-round(w/2), y+round(h*1.5)), (x+round(w/2), y+round(h*2.5)), (150, 150, 150), thickness)
                            if finalwindow == True:
                                cv2.rectangle(final_frame, (x-round(w/2), y-round(h/2)), (x+round(w/2), y+round(h/2)), (150, 150, 150), thickness)
                                cv2.rectangle(final_frame, (x-round(w/2), y+round(h/2)), (x+round(w/2), y+round(h*1.5)), (150, 150, 150), thickness)
                                cv2.rectangle(final_frame, (x-round(w/2), y+round(h*1.5)), (x+round(w/2), y+round(h*2.5)), (150, 150, 150), thickness)

        except Exception as e:
            print(&#34;TrafficLightDetection - Tracking/YOLO Error: &#34; + str(e))
    else:
        if anywindowopen == True:
            for i in range(len(coordinates)):
                x, y, w, h, state = coordinates[i]
                radius = round((w+h)/4)
                thickness = round((w+h)/30)
                if thickness &lt; 1:
                    thickness = 1
                if state == &#34;Red&#34;:
                    color = (0, 0, 255)
                    cv2.circle(final_frame, (x,y-h), radius, color, thickness)
                    cv2.circle(filtered_frame_bw, (x,y-h), radius, (255, 255, 255), thickness)
                    cv2.circle(filtered_frame_red_yellow_green, (x,y-h), radius,color, thickness)
                    cv2.rectangle(final_frame, (x-w, y-h*2), (x+w, y+h*2), color, radius)
                    cv2.rectangle(filtered_frame_red_yellow_green, (x-w, y-h*2), (x+w, y+h*2), color, radius)
                    if grayscalewindow == True:
                        cv2.rectangle(filtered_frame_bw, (x-round(w/2), y-round(h*1.5)), (x+round(w/2), y-round(h/2)), (150, 150, 150), thickness)
                    if redyellowgreenwindow == True:
                        cv2.rectangle(filtered_frame_red_yellow_green, (x-round(w/2), y-round(h*1.5)), (x+round(w/2), y-round(h/2)), (150, 150, 150), thickness)
                        cv2.rectangle(filtered_frame_red_yellow_green, (x-round(w/2), y-round(h/2)), (x+round(w/2), y+round(h/2)), (150, 150, 150), thickness)
                        cv2.rectangle(filtered_frame_red_yellow_green, (x-round(w/2), y+round(h/2)), (x+round(w/2), y+round(h*1.5)), (150, 150, 150), thickness)
                    if finalwindow == True:
                        cv2.rectangle(final_frame, (x-round(w/2), y-round(h*1.5)), (x+round(w/2), y-round(h/2)), (150, 150, 150), thickness)
                        cv2.rectangle(final_frame, (x-round(w/2), y-round(h/2)), (x+round(w/2), y+round(h/2)), (150, 150, 150), thickness)
                        cv2.rectangle(final_frame, (x-round(w/2), y+round(h/2)), (x+round(w/2), y+round(h*1.5)), (150, 150, 150), thickness)
                if state == &#34;Yellow&#34;:
                    color = (0, 255, 255)
                    cv2.circle(final_frame, (x,y), radius, color, thickness)
                    cv2.circle(filtered_frame_bw, (x,y), radius, (255, 255, 255), thickness)
                    cv2.circle(filtered_frame_red_yellow_green, (x,y), radius,color, thickness)
                    cv2.rectangle(final_frame, (x-w, y-h*2), (x+w, y+h*2), color, radius)
                    cv2.rectangle(filtered_frame_red_yellow_green, (x-w, y-h*2), (x+w, y+h*2), color, radius)
                    if grayscalewindow == True:
                        cv2.rectangle(filtered_frame_bw, (x-round(w/2), y-round(h/2)), (x+round(w/2), y+round(h/2)), (150, 150, 150), thickness)
                    if redyellowgreenwindow == True:
                        cv2.rectangle(filtered_frame_red_yellow_green, (x-round(w/2), y-round(h*1.5)), (x+round(w/2), y-round(h/2)), (150, 150, 150), thickness)
                        cv2.rectangle(filtered_frame_red_yellow_green, (x-round(w/2), y-round(h/2)), (x+round(w/2), y+round(h/2)), (150, 150, 150), thickness)
                        cv2.rectangle(filtered_frame_red_yellow_green, (x-round(w/2), y+round(h/2)), (x+round(w/2), y+round(h*1.5)), (150, 150, 150), thickness)
                    if finalwindow == True:
                        cv2.rectangle(final_frame, (x-round(w/2), y-round(h*1.5)), (x+round(w/2), y-round(h/2)), (150, 150, 150), thickness)
                        cv2.rectangle(final_frame, (x-round(w/2), y-round(h/2)), (x+round(w/2), y+round(h/2)), (150, 150, 150), thickness)
                        cv2.rectangle(final_frame, (x-round(w/2), y+round(h/2)), (x+round(w/2), y+round(h*1.5)), (150, 150, 150), thickness)
                if state == &#34;Green&#34;:
                    color = (0, 255, 0)
                    cv2.circle(final_frame, (x,y+h*2), radius, color, thickness)
                    cv2.circle(filtered_frame_bw, (x,y+h*2), radius, (255, 255, 255), thickness)
                    cv2.circle(filtered_frame_red_yellow_green, (x,y+h*2), radius,color, thickness)
                    cv2.rectangle(final_frame, (x-w, y-h), (x+w, y+h*3), color, radius)
                    cv2.rectangle(filtered_frame_red_yellow_green, (x-w, y-h), (x+w, y+h*3), color, radius)
                    if grayscalewindow == True:
                        cv2.rectangle(filtered_frame_bw, (x-round(w/2), y+round(h*1.5)), (x+round(w/2), y+round(h*2.5)), (150, 150, 150), thickness)
                    if redyellowgreenwindow == True:
                        cv2.rectangle(filtered_frame_red_yellow_green, (x-round(w/2), y-round(h/2)), (x+round(w/2), y+round(h/2)), (150, 150, 150), thickness)
                        cv2.rectangle(filtered_frame_red_yellow_green, (x-round(w/2), y+round(h/2)), (x+round(w/2), y+round(h*1.5)), (150, 150, 150), thickness)
                        cv2.rectangle(filtered_frame_red_yellow_green, (x-round(w/2), y+round(h*1.5)), (x+round(w/2), y+round(h*2.5)), (150, 150, 150), thickness)
                    if finalwindow == True:
                        cv2.rectangle(final_frame, (x-round(w/2), y-round(h/2)), (x+round(w/2), y+round(h/2)), (150, 150, 150), thickness)
                        cv2.rectangle(final_frame, (x-round(w/2), y+round(h/2)), (x+round(w/2), y+round(h*1.5)), (150, 150, 150), thickness)
                        cv2.rectangle(final_frame, (x-round(w/2), y+round(h*1.5)), (x+round(w/2), y+round(h*2.5)), (150, 150, 150), thickness)

    try:
        if yolo_detection == True:
            data_simple = None
            for i in range(len(trafficlights)):
                coord, id, approved = trafficlights[i]
                x, y, w, h, state = coord
                if state == &#34;Red&#34; and approved == True:
                    data_simple = &#34;Red&#34;
                    break
                elif state == &#34;Yellow&#34; and approved == True:
                    data_simple = &#34;Yellow&#34;
                    break
                elif state == &#34;Green&#34; and approved == True:
                    data_simple = &#34;Green&#34;
                    break
            data[&#34;TrafficLightDetection&#34;] = {}
            data[&#34;TrafficLightDetection&#34;][&#34;simple&#34;] = data_simple
            data[&#34;TrafficLightDetection&#34;][&#34;detailed&#34;] = trafficlights
        else:
            data_simple = None
            for i in range(len(coordinates)):
                x, y, w, h, state = coordinates[i]
                if state == &#34;Red&#34;:
                    data_simple = &#34;Red&#34;
                    break
                elif state == &#34;Yellow&#34;:
                    data_simple = &#34;Yellow&#34;
                    break
                elif state == &#34;Green&#34;:
                    data_simple = &#34;Green&#34;
                    break
            data[&#34;TrafficLightDetection&#34;] = {}
            data[&#34;TrafficLightDetection&#34;][&#34;simple&#34;] = data_simple
            data[&#34;TrafficLightDetection&#34;][&#34;detailed&#34;] = coordinates
    except Exception as e:
        print(&#34;TrafficLightDetection - Data Error: &#34; + str(e))

    if reset_window == True:
        if grayscalewindow == False:
            try:
                cv2.destroyWindow(&#39;Traffic Light Detection - B/W&#39;)
            except:
                pass
        if redyellowgreenwindow == False:
            try:
                cv2.destroyWindow(&#39;Traffic Light Detection - Red/Yellow/Green&#39;)
            except:
                pass
        if finalwindow == False:
            try:
                cv2.destroyWindow(&#39;Traffic Light Detection - Final&#39;)
            except:
                pass

    if grayscalewindow == True:
        window_handle = ctypes.windll.user32.FindWindowW(None, &#39;Traffic Light Detection - B/W&#39;)
        if window_handle == 0 or reset_window == True:
            cv2.namedWindow(&#39;Traffic Light Detection - B/W&#39;, cv2.WINDOW_NORMAL)
            cv2.resizeWindow(&#39;Traffic Light Detection - B/W&#39;, round(windowwidth*windowscale), round(windowheight*windowscale))
            cv2.setWindowProperty(&#39;Traffic Light Detection - B/W&#39;, cv2.WND_PROP_TOPMOST, 1)
        cv2.imshow(&#39;Traffic Light Detection - B/W&#39;, filtered_frame_bw)
    if redyellowgreenwindow == True:      
        if performancemode == False:
            if detectyellowlight == False:
                window_handle = ctypes.windll.user32.FindWindowW(None, &#39;Traffic Light Detection - Red/Yellow/Green&#39;)
                if window_handle == 0 or reset_window == True:
                    cv2.namedWindow(&#39;Traffic Light Detection - Red/Yellow/Green&#39;, cv2.WINDOW_NORMAL)
                    cv2.resizeWindow(&#39;Traffic Light Detection - Red/Yellow/Green&#39;, round(windowwidth*windowscale), round(windowheight*windowscale))
                    cv2.setWindowProperty(&#39;Traffic Light Detection - Red/Yellow/Green&#39;, cv2.WND_PROP_TOPMOST, 1)
                cv2.imshow(&#39;Traffic Light Detection - Red/Yellow/Green&#39;, filtered_frame_red_yellow_green)
            else:
                window_handle = ctypes.windll.user32.FindWindowW(None, &#39;Traffic Light Detection - Red/Yellow/Green&#39;)
                if window_handle == 0 or reset_window == True:
                    cv2.namedWindow(&#39;Traffic Light Detection - Red/Yellow/Green&#39;, cv2.WINDOW_NORMAL)
                    cv2.resizeWindow(&#39;Traffic Light Detection - Red/Yellow/Green&#39;, round(windowwidth*windowscale), round(windowheight*windowscale))
                    cv2.setWindowProperty(&#39;Traffic Light Detection - Red/Yellow/Green&#39;, cv2.WND_PROP_TOPMOST, 1)
                cv2.imshow(&#39;Traffic Light Detection - Red/Yellow/Green&#39;, filtered_frame_red_yellow_green)
        else:
            window_handle = ctypes.windll.user32.FindWindowW(None, &#39;Traffic Light Detection - Red/Yellow/Green&#39;)
            if window_handle == 0 or reset_window == True:
                cv2.namedWindow(&#39;Traffic Light Detection - Red/Yellow/Green&#39;, cv2.WINDOW_NORMAL)
                cv2.resizeWindow(&#39;Traffic Light Detection - Red/Yellow/Green&#39;, round(windowwidth*windowscale), round(windowheight*windowscale))
                cv2.setWindowProperty(&#39;Traffic Light Detection - Red/Yellow/Green&#39;, cv2.WND_PROP_TOPMOST, 1)
            cv2.imshow(&#39;Traffic Light Detection - Red/Yellow/Green&#39;, filtered_frame_red_yellow_green)
    if finalwindow == True:
        window_handle = ctypes.windll.user32.FindWindowW(None, &#39;Traffic Light Detection - Final&#39;)
        if window_handle == 0 or reset_window == True:
            cv2.namedWindow(&#39;Traffic Light Detection - Final&#39;, cv2.WINDOW_NORMAL)
            cv2.resizeWindow(&#39;Traffic Light Detection - Final&#39;, round(windowwidth*windowscale), round(windowheight*windowscale))
            cv2.setWindowProperty(&#39;Traffic Light Detection - Final&#39;, cv2.WND_PROP_TOPMOST, 1)
        cv2.imshow(&#39;Traffic Light Detection - Final&#39;, final_frame)
    if reset_window == True:
        reset_window = False
    return data # Plugins need to ALWAYS return the data


# Plugins need to all also have the onEnable and onDisable functions
def onEnable():
    UpdateSettings()
    loadYOLO()
    pass

def onDisable():
    pass

class UI():
    try: 
        
        def __init__(self, master) -&gt; None:
            self.master = master 
            self.exampleFunction()
            resizeWindow(850,600)
        
        def destroy(self):
            self.done = True
            self.root.destroy()
            del self

        def tabFocused(self):
            resizeWindow(850,600)
            
        def UpdateSliderValue_scale(self):
            self.scale.set(self.scaleSlider.get())
            settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;scale&#34;, self.scaleSlider.get())
            UpdateSettings()
        def UpdateSliderValue_x1ofsc(self):
            self.x1ofsc.set(self.x1ofscSlider.get())
            settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;x1ofsc&#34;, self.x1ofscSlider.get())
            UpdateSettings()
        def UpdateSliderValue_y1ofsc(self):
            self.y1ofsc.set(self.y1ofscSlider.get())
            settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;y1ofsc&#34;, self.y1ofscSlider.get())
            UpdateSettings()
        def UpdateSliderValue_x2ofsc(self):
            self.x2ofsc.set(self.x2ofscSlider.get())
            settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;x2ofsc&#34;, self.x2ofscSlider.get())
            UpdateSettings()
        def UpdateSliderValue_y2ofsc(self):
            self.y2ofsc.set(self.y2ofscSlider.get())
            settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;y2ofsc&#34;, self.y2ofscSlider.get())
            UpdateSettings()
        def UpdateSliderValue_windowwidth(self):
            self.windowwidth.set(self.windowwidthSlider.get())
            settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;outputwindowwidth&#34;, self.windowwidthSlider.get())
            UpdateSettings()
        def UpdateSliderValue_windowheight(self):
            self.windowheight.set(self.windowheightSlider.get())
            settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;outputwindowheight&#34;, self.windowheightSlider.get())
            UpdateSettings()
        def UpdateSliderValue_minrectsize(self):
            self.minrectsize.set(self.minrectsizeSlider.get())
            settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;minrectsize&#34;, self.minrectsizeSlider.get())
            UpdateSettings()
        def UpdateSliderValue_maxrectsize(self):
            self.maxrectsize.set(self.maxrectsizeSlider.get())
            settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;maxrectsize&#34;, self.maxrectsizeSlider.get())
            UpdateSettings()
        
        def exampleFunction(self):
            
            try:
                self.root.destroy() 
            except: pass
            
            self.root = tk.Canvas(self.master, width=750, height=600, border=0, highlightthickness=0)
            self.root.grid_propagate(0) 
            self.root.pack_propagate(0)
            
            notebook = ttk.Notebook(self.root)
            notebook.pack(anchor=&#34;center&#34;, fill=&#34;both&#34;, expand=True)
            
            generalFrame = ttk.Frame(notebook)
            generalFrame.pack()
            screencaptureFrame = ttk.Frame(notebook)
            screencaptureFrame.pack()
            outputwindowFrame = ttk.Frame(notebook)
            outputwindowFrame.pack()
            trackeraiFrame = ttk.Frame(notebook)
            trackeraiFrame.pack()
            advancedFrame = ttk.Frame(notebook)
            advancedFrame.pack()

            advancedNotebook = ttk.Notebook(advancedFrame)
            advancedNotebook.grid_anchor(&#34;center&#34;)
            advancedNotebook.grid()
            
            colorsettingsFrame = ttk.Frame(advancedNotebook)
            colorsettingsFrame.pack()
            filtersFrame = ttk.Frame(advancedNotebook)
            filtersFrame.pack()


            colorsettingsFrame.columnconfigure(0, weight=1)
            colorsettingsFrame.columnconfigure(1, weight=1)
            colorsettingsFrame.columnconfigure(2, weight=1)
            helpers.MakeLabel(colorsettingsFrame, &#34;Color Settings&#34;, 0, 0, font=(&#34;Robot&#34;, 12, &#34;bold&#34;), columnspan=7)

            filtersFrame.columnconfigure(0, weight=1)
            filtersFrame.columnconfigure(1, weight=1)
            filtersFrame.columnconfigure(2, weight=1)
            helpers.MakeLabel(filtersFrame, &#34;Filters&#34;, 0, 0, font=(&#34;Robot&#34;, 12, &#34;bold&#34;), columnspan=3)

            generalFrame.columnconfigure(0, weight=1)
            generalFrame.columnconfigure(1, weight=1)
            generalFrame.columnconfigure(2, weight=1)
            helpers.MakeLabel(generalFrame, &#34;General&#34;, 0, 0, font=(&#34;Robot&#34;, 12, &#34;bold&#34;), columnspan=3)
            
            screencaptureFrame.columnconfigure(0, weight=1)
            screencaptureFrame.columnconfigure(1, weight=1)
            screencaptureFrame.columnconfigure(2, weight=1)
            helpers.MakeLabel(screencaptureFrame, &#34;Screen Capture&#34;, 0, 0, font=(&#34;Robot&#34;, 12, &#34;bold&#34;), columnspan=3)

            outputwindowFrame.columnconfigure(0, weight=1)
            outputwindowFrame.columnconfigure(1, weight=1)
            outputwindowFrame.columnconfigure(2, weight=1)
            helpers.MakeLabel(outputwindowFrame, &#34;Output Window&#34;, 0, 0, font=(&#34;Robot&#34;, 12, &#34;bold&#34;), columnspan=3)

            trackeraiFrame.columnconfigure(0, weight=1)
            trackeraiFrame.columnconfigure(1, weight=1)
            trackeraiFrame.columnconfigure(2, weight=1)
            helpers.MakeLabel(trackeraiFrame, &#34;Tracker/AI&#34;, 0, 0, font=(&#34;Robot&#34;, 12, &#34;bold&#34;), columnspan=7)

            advancedFrame.columnconfigure(0, weight=1)
            advancedFrame.columnconfigure(1, weight=1)
            advancedFrame.columnconfigure(2, weight=1)
            helpers.MakeLabel(advancedFrame, &#34;Advanced&#34;, 0, 0, font=(&#34;Robot&#34;, 12, &#34;bold&#34;), columnspan=7)
            

            notebook.add(generalFrame, text=Translate(&#34;General&#34;))
            notebook.add(screencaptureFrame, text=Translate(&#34;ScreenCapture&#34;))
            notebook.add(outputwindowFrame, text=Translate(&#34;OutputWindow&#34;))
            notebook.add(trackeraiFrame, text=Translate(&#34;Tracker/AI&#34;))
            notebook.add(advancedFrame, text=Translate(&#34;Advanced&#34;))
            advancedNotebook.add(colorsettingsFrame, text=Translate(&#34;ColorSettings&#34;))
            advancedNotebook.add(filtersFrame, text=Translate(&#34;Filters&#34;))
            
            self.root.pack(anchor=&#34;center&#34;, expand=False)
            self.root.update()


            helpers.MakeCheckButton(outputwindowFrame, &#34;Final Window\n--------------------\nIf enabled, the app creates a window with the result of the traffic light detection.&#34;, &#34;TrafficLightDetection&#34;, &#34;finalwindow&#34;, 1, 0, width=80, callback=lambda:UpdateSettings())
            helpers.MakeCheckButton(outputwindowFrame, &#34;Grayscale Window\n---------------------------\nIf enabled, the app creates a window with the color masks combined in a grayscaled frame.&#34;, &#34;TrafficLightDetection&#34;, &#34;grayscalewindow&#34;, 2, 0, width=80, callback=lambda:UpdateSettings())
            helpers.MakeCheckButton(outputwindowFrame, &#34;Red/Yellow/Green Window\n----------------------------\nIf enabled, the app creates a window with the color masks combined in a frame.&#34;, &#34;TrafficLightDetection&#34;, &#34;redyellowgreenwindow&#34;, 3, 0, width=80, callback=lambda:UpdateSettings())
            helpers.MakeCheckButton(outputwindowFrame, &#34;Automatic Windowsize\n---------------------------------\nIf enabled, the Window Width and Window Height sliders will no longer have any effect\nand the output window keeps the aspect ratio of the captured frame. Set the size of the\noutput window with the Window Scale slider.&#34;, &#34;TrafficLightDetection&#34;, &#34;automaticwindowsize&#34;, 4, 0, width=80, callback=lambda:UpdateSettings())
            helpers.MakeEmptyLine(outputwindowFrame,5,0)

            helpers.MakeCheckButton(generalFrame, &#34;Yellow Light Detection (not recommended)\n-------------------------------------------------------------\nIf enabled, the trafficlight detection tries to detect yellow traffic\nlights, but it is not recommended because it causes more wrong\ndetected traffic lights.&#34;, &#34;TrafficLightDetection&#34;, &#34;detectyellowlight&#34;, 4, 0, width=60, callback=lambda:UpdateSettings())
            helpers.MakeCheckButton(generalFrame, &#34;Performance Mode (recommended)\n---------------------------------------------------\nIf enabled, the traffic light detection only detects red traffic lights,\nwhich increases performance, but does not reduce detection accuracy.&#34;, &#34;TrafficLightDetection&#34;, &#34;performancemode&#34;, 5, 0, width=60, callback=lambda:UpdateSettings())
            helpers.MakeCheckButton(generalFrame, &#34;Advanced Settings\n---------------------------\nIf enabled, the traffic light detection uses the settings you set in\nthe Advanced tab. (could have a bad impact on performance)&#34;, &#34;TrafficLightDetection&#34;, &#34;advancedmode&#34;, 6, 0, width=60, callback=lambda:UpdateSettings())
            helpers.MakeEmptyLine(generalFrame,7,0)

            helpers.MakeCheckButton(filtersFrame, &#34;Rect Size Filter&#34;, &#34;TrafficLightDetection&#34;, &#34;rectsizefilter&#34;, 3, 0, width=60, callback=lambda:UpdateSettings())
            helpers.MakeCheckButton(filtersFrame, &#34;Width Height Ratio Filter&#34;, &#34;TrafficLightDetection&#34;, &#34;widthheightratiofilter&#34;, 4, 0, width=60, callback=lambda:UpdateSettings())
            helpers.MakeCheckButton(filtersFrame, &#34;Pixel Percentage Filter&#34;, &#34;TrafficLightDetection&#34;, &#34;pixelpercentagefilter&#34;, 5, 0, width=60, callback=lambda:UpdateSettings())
            helpers.MakeCheckButton(filtersFrame, &#34;Other Lights Filter&#34;, &#34;TrafficLightDetection&#34;, &#34;otherlightsofffilter&#34;, 6, 0, width=60, callback=lambda:UpdateSettings())

            helpers.MakeCheckButton(trackeraiFrame, &#34;Do Yolo Detection confirmation\n---------------------------------------------\nIf enabled, the app tracks the detected traffic lights and confirms them with the YOLO object detection.\nWhat this means: higher accuracy, but a small lag every time the detection detects a new traffic light.&#34;, &#34;TrafficLightDetection&#34;, &#34;yolo_detection&#34;, 1, 0, width=100, callback=lambda:UpdateSettings())
            helpers.MakeCheckButton(trackeraiFrame, &#34;Show unconfirmed traffic lights\n--------------------------------------------\nIf enabled, the app will show unconfirmed or wrongly detected traffic lights in gray in the output window.&#34;, &#34;TrafficLightDetection&#34;, &#34;yolo_showunconfirmed&#34;, 2, 0, width=100, callback=lambda:UpdateSettings())
            helpers.MakeEmptyLine(trackeraiFrame,3,0)
            helpers.MakeLabel(trackeraiFrame, &#34;YOLOv5 Model:&#34;, 4, 0, sticky=&#34;nw&#34;)
            model_ui = tk.StringVar() 
            previous_model_ui = settings.GetSettings(&#34;TrafficLightDetection&#34;, &#34;yolo_model&#34;)
            if previous_model_ui == &#34;yolov5n&#34;:
                model_ui.set(&#34;yolov5n&#34;)
            if previous_model_ui == &#34;yolov5s&#34;:
                model_ui.set(&#34;yolov5s&#34;)
            if previous_model_ui == &#34;yolov5m&#34;:
                model_ui.set(&#34;yolov5m&#34;)
            if previous_model_ui == &#34;yolov5l&#34;:
                model_ui.set(&#34;yolov5l&#34;)
            if previous_model_ui == &#34;yolov5x&#34;:
                model_ui.set(&#34;yolov5x&#34;)
            def model_selection():
                self.model_ui = model_ui.get()
            yolov5n = ttk.Radiobutton(trackeraiFrame, text=&#34;YOLOv5n (fastest, lowest accuracy) RECOMMENDED&#34;, variable=model_ui, value=&#34;yolov5n&#34;, command=model_selection)
            yolov5n.grid(row=5, column=0, sticky=&#34;nw&#34;)
            yolov5s = ttk.Radiobutton(trackeraiFrame, text=&#34;YOLOv5s (fast, low accuracy)&#34;, variable=model_ui, value=&#34;yolov5s&#34;, command=model_selection)
            yolov5s.grid(row=6, column=0, sticky=&#34;nw&#34;)
            yolov5m = ttk.Radiobutton(trackeraiFrame, text=&#34;YOLOv5m (slow, medium accuracy)&#34;, variable=model_ui, value=&#34;yolov5m&#34;, command=model_selection)
            yolov5m.grid(row=7, column=0, sticky=&#34;nw&#34;)
            yolov5l = ttk.Radiobutton(trackeraiFrame, text=&#34;YOLOv5l (slow, high accuracy)&#34;, variable=model_ui, value=&#34;yolov5l&#34;, command=model_selection)
            yolov5l.grid(row=8, column=0, sticky=&#34;nw&#34;)
            yolov5x = ttk.Radiobutton(trackeraiFrame, text=&#34;YOLOv5x (slowest, highest accuracy)&#34;, variable=model_ui, value=&#34;yolov5x&#34;, command=model_selection)
            yolov5x.grid(row=9, column=0, sticky=&#34;nw&#34;)
            model_selection()
            helpers.MakeButton(trackeraiFrame, &#34;Save and Load Model\n-------------------------------\nLoading the model could take some time.\nIt&#39;s normal that the app won&#39;t respond for a while.&#34;, self.save_and_load_model, 10, 0, width=50, sticky=&#34;nw&#34;)

            helpers.MakeCheckButton(screencaptureFrame, &#34;Use Full Frame\n----------------------\nIf enabled, the screencapture for the traffic light detection uses the top ⅔ of the screen for\nthe traffic light detection. (not recommended, could have a bad impact on performance)\n\nTo set own screencapture coordinates disable Use Full Frame and use sliders below.&#34;, &#34;TrafficLightDetection&#34;, &#34;usefullframe&#34;, 1, 0, width=80, callback=lambda:UpdateSettings())
            
            self.x1ofscSlider = tk.Scale(screencaptureFrame, from_=0, to=screen_width-1, resolution=1, orient=tk.HORIZONTAL, length=460, command=lambda x: self.UpdateSliderValue_x1ofsc())
            self.x1ofscSlider.set(settings.GetSettings(&#34;TrafficLightDetection&#34;, &#34;x1ofsc&#34;, 0))
            self.x1ofscSlider.grid(row=3, column=0, padx=10, pady=0, columnspan=2)
            self.x1ofsc = helpers.MakeComboEntry(screencaptureFrame, &#34;X1 (topleft)&#34;, &#34;TrafficLightDetection&#34;, &#34;x1ofsc&#34;, 3,0)

            self.y1ofscSlider = tk.Scale(screencaptureFrame, from_=0, to=screen_height-1, resolution=1, orient=tk.HORIZONTAL, length=460, command=lambda x: self.UpdateSliderValue_y1ofsc())
            self.y1ofscSlider.set(settings.GetSettings(&#34;TrafficLightDetection&#34;, &#34;y1ofsc&#34;, 0))
            self.y1ofscSlider.grid(row=5, column=0, padx=10, pady=0, columnspan=2)
            self.y1ofsc = helpers.MakeComboEntry(screencaptureFrame, &#34;Y1 (topleft)&#34;, &#34;TrafficLightDetection&#34;, &#34;y1ofsc&#34;, 5,0)

            self.x2ofscSlider = tk.Scale(screencaptureFrame, from_=0, to=screen_width-1, resolution=1, orient=tk.HORIZONTAL, length=460, command=lambda x: self.UpdateSliderValue_x2ofsc())
            self.x2ofscSlider.set(settings.GetSettings(&#34;TrafficLightDetection&#34;, &#34;x2ofsc&#34;, screen_width-1))
            self.x2ofscSlider.grid(row=7, column=0, padx=10, pady=0, columnspan=2)
            self.x2ofsc = helpers.MakeComboEntry(screencaptureFrame, &#34;X2 (buttomright)&#34;, &#34;TrafficLightDetection&#34;, &#34;x2ofsc&#34;, 7,0)

            self.y2ofscSlider = tk.Scale(screencaptureFrame, from_=0, to=screen_height-1, resolution=1, orient=tk.HORIZONTAL, length=460, command=lambda x: self.UpdateSliderValue_y2ofsc())
            self.y2ofscSlider.set(settings.GetSettings(&#34;TrafficLightDetection&#34;, &#34;y2ofsc&#34;, round(screen_height/1.5)-1))
            self.y2ofscSlider.grid(row=9, column=0, padx=10, pady=0, columnspan=2)
            self.y2ofsc = helpers.MakeComboEntry(screencaptureFrame, &#34;Y2 (buttomright)&#34;, &#34;TrafficLightDetection&#34;, &#34;y2ofsc&#34;, 9,0)

            helpers.MakeButton(screencaptureFrame, &#34;Open/Refresh preview&#34;, lambda: screencapture_open_refresh(), 11, 0, width=30, sticky=&#34;w&#34;)
            helpers.MakeButton(screencaptureFrame, &#34;Close preview&#34;, lambda: screencapture_close(), 12, 0, width=30, sticky=&#34;w&#34;)

            def screencapture_open_refresh():
                self.UpdateSliderValue_x1ofsc()
                self.UpdateSliderValue_y1ofsc()
                self.UpdateSliderValue_x2ofsc()
                self.UpdateSliderValue_y2ofsc()
                if settings.GetSettings(&#34;TrafficLightDetection&#34;, &#34;usefullframe&#34;, True) == False:
                    x1_preview = self.x1ofscSlider.get()
                    y1_preview = self.y1ofscSlider.get()
                    x2_preview = self.x2ofscSlider.get()
                    y2_preview = self.y2ofscSlider.get()
                    screenshot = cv2.cvtColor(np.array(pyautogui.screenshot(region=(x1_preview, y1_preview, x2_preview - x1_preview, y2_preview - y1_preview))), cv2.COLOR_RGB2BGR)
                else:
                    x1_preview = 0
                    y1_preview = 0
                    x2_preview = screen_width-1
                    y2_preview = round(screen_height/1.5)-1
                    screenshot = cv2.cvtColor(np.array(pyautogui.screenshot(region=(x1_preview, y1_preview, x2_preview - x1_preview, y2_preview - y1_preview))), cv2.COLOR_RGB2BGR)
                    current_text = &#39;&#34;Use Full Frame&#34; enabled, disable to set own screencapture area&#39;
                    width_target_current_text = (x2_preview - x1_preview)*0.9
                    fontscale_current_text = 1
                    textsize_current_text, _ = cv2.getTextSize(current_text, cv2.FONT_HERSHEY_SIMPLEX, fontscale_current_text, 1)
                    width_current_text, height_current_text = textsize_current_text
                    max_count_current_text = 3
                    while width_current_text != width_target_current_text:
                        fontscale_current_text *= width_target_current_text / width_current_text if width_current_text != 0 else 1
                        textsize_current_text, _ = cv2.getTextSize(current_text, cv2.FONT_HERSHEY_SIMPLEX, fontscale_current_text, 1)
                        width_current_text, height_current_text = textsize_current_text
                        max_count_current_text -= 1
                        if max_count_current_text &lt;= 0:
                            break
                    thickness_current_text = round(fontscale_current_text*2)
                    if thickness_current_text &lt;= 0:
                        thickness_current_text = 1
                    cv2.putText(screenshot, current_text, (round((x2-x1)/2 - width_current_text/2), height_current_text*2), cv2.FONT_HERSHEY_SIMPLEX, fontscale_current_text, (0, 0, 255), thickness_current_text)
                cv2.namedWindow(&#39;Screencapture Preview&#39;, cv2.WINDOW_NORMAL)
                cv2.setWindowProperty(&#39;Screencapture Preview&#39;, cv2.WND_PROP_TOPMOST, 1)
                cv2.resizeWindow(&#39;Screencapture Preview&#39;, round((x2-x1)/2), round((y2-y1)/2))
                cv2.imshow(&#39;Screencapture Preview&#39;, screenshot)
                cv2.waitKey(1)
                
            def screencapture_close():
                try: 
                    cv2.destroyWindow(&#39;Screencapture Preview&#39;)
                except: 
                    pass

            self.windowwidthSlider = tk.Scale(outputwindowFrame, from_=round(screen_width/20), to=screen_width, resolution=1, orient=tk.HORIZONTAL, length=480, command=lambda x: self.UpdateSliderValue_windowwidth())
            self.windowwidthSlider.set(settings.GetSettings(&#34;TrafficLightDetection&#34;, &#34;outputwindowwidth&#34;, round(screen_width/2)))
            self.windowwidthSlider.grid(row=6, column=0, padx=10, pady=0, columnspan=2)
            self.windowwidth = helpers.MakeComboEntry(outputwindowFrame, &#34;Window Width&#34;, &#34;TrafficLightDetection&#34;, &#34;outputwindowwidth&#34;, 6,0, labelwidth=13, width=10)

            self.windowheightSlider = tk.Scale(outputwindowFrame, from_=round(screen_height/20), to=screen_height, resolution=1, orient=tk.HORIZONTAL, length=480, command=lambda x: self.UpdateSliderValue_windowheight())
            self.windowheightSlider.set(settings.GetSettings(&#34;TrafficLightDetection&#34;, &#34;outputwindowheight&#34;, round(screen_height/3)))
            self.windowheightSlider.grid(row=7, column=0, padx=10, pady=0, columnspan=2)
            self.windowheight = helpers.MakeComboEntry(outputwindowFrame, &#34;Window Height&#34;, &#34;TrafficLightDetection&#34;, &#34;outputwindowheight&#34;, 7,0, labelwidth=13, width=10)

            self.scaleSlider = tk.Scale(outputwindowFrame, from_=0.1, to=2, resolution=0.01, orient=tk.HORIZONTAL, length=480, command=lambda x: self.UpdateSliderValue_scale())
            self.scaleSlider.set(settings.GetSettings(&#34;TrafficLightDetection&#34;, &#34;scale&#34;, 0.5))
            self.scaleSlider.grid(row=8, column=0, padx=10, pady=0, columnspan=2)
            self.scale = helpers.MakeComboEntry(outputwindowFrame, &#34;Window Scale&#34;, &#34;TrafficLightDetection&#34;, &#34;scale&#34;, 8,0, labelwidth=13, width=10)

            self.minrectsizeSlider = tk.Scale(filtersFrame, from_=1, to=round(screen_width / 2), resolution=1, orient=tk.HORIZONTAL, length=700, command=lambda x: self.UpdateSliderValue_minrectsize())
            self.minrectsizeSlider.set(settings.GetSettings(&#34;TrafficLightDetection&#34;, &#34;minrectsize&#34;, round(screen_width / 240)))
            self.minrectsizeSlider.grid(row=7, column=0, padx=10, pady=0, columnspan=2)
            self.minrectsize = helpers.MakeComboEntry(filtersFrame, &#34;Min. Traffic Light Size Filter&#34;, &#34;TrafficLightDetection&#34;, &#34;minrectsize&#34;, 8,0, labelwidth=80, width=20)

            self.maxrectsizeSlider = tk.Scale(filtersFrame, from_=1, to=round(screen_width / 2), resolution=1, orient=tk.HORIZONTAL, length=700, command=lambda x: self.UpdateSliderValue_maxrectsize())
            self.maxrectsizeSlider.set(settings.GetSettings(&#34;TrafficLightDetection&#34;, &#34;maxrectsize&#34;, round(screen_width / 10)))
            self.maxrectsizeSlider.grid(row=9, column=0, padx=10, pady=0, columnspan=2)
            self.maxrectsize = helpers.MakeComboEntry(filtersFrame, &#34;Max. Traffic Light Size Filter&#34;, &#34;TrafficLightDetection&#34;, &#34;maxrectsize&#34;, 10,0, labelwidth=80, width=20)

            self.upperredr = helpers.MakeComboEntry(colorsettingsFrame, &#34;RED:         Upper R:&#34;, &#34;TrafficLightDetection&#34;, &#34;upperred_r&#34;, 2, 0, labelwidth=20, width=7)
            self.upperredg = helpers.MakeComboEntry(colorsettingsFrame, &#34;Upper G:&#34;, &#34;TrafficLightDetection&#34;, &#34;upperred_g&#34;, 2, 2, labelwidth=13, width=7)
            self.upperredb = helpers.MakeComboEntry(colorsettingsFrame, &#34;Upper B:&#34;, &#34;TrafficLightDetection&#34;, &#34;upperred_b&#34;, 2, 4, labelwidth=13, width=7)
            self.lowerredr = helpers.MakeComboEntry(colorsettingsFrame, &#34;RED:         Lower R:&#34;, &#34;TrafficLightDetection&#34;, &#34;lowerred_r&#34;, 3, 0, labelwidth=20, width=7)
            self.lowerredg = helpers.MakeComboEntry(colorsettingsFrame, &#34;Lower G:&#34;, &#34;TrafficLightDetection&#34;, &#34;lowerred_g&#34;, 3, 2, labelwidth=13, width=7)
            self.lowerredb = helpers.MakeComboEntry(colorsettingsFrame, &#34;Lower B:&#34;, &#34;TrafficLightDetection&#34;, &#34;lowerred_b&#34;, 3, 4, labelwidth=13, width=7)
            self.upperyellowr = helpers.MakeComboEntry(colorsettingsFrame, &#34;YELLOW:  Upper R:&#34;, &#34;TrafficLightDetection&#34;, &#34;upperyellow_r&#34;, 4, 0, labelwidth=20, width=7)
            self.upperyellowg = helpers.MakeComboEntry(colorsettingsFrame, &#34;Upper G:&#34;, &#34;TrafficLightDetection&#34;, &#34;upperyellow_g&#34;, 4, 2, labelwidth=13, width=7)
            self.upperyellowb = helpers.MakeComboEntry(colorsettingsFrame, &#34;Upper B:&#34;, &#34;TrafficLightDetection&#34;, &#34;upperyellow_b&#34;, 4, 4, labelwidth=13, width=7)
            self.loweryellowr = helpers.MakeComboEntry(colorsettingsFrame, &#34;YELLOW:  Lower R:&#34;, &#34;TrafficLightDetection&#34;, &#34;loweryellow_r&#34;, 5, 0, labelwidth=20, width=7)
            self.loweryellowg = helpers.MakeComboEntry(colorsettingsFrame, &#34;Lower G:&#34;, &#34;TrafficLightDetection&#34;, &#34;loweryellow_g&#34;, 5, 2, labelwidth=13, width=7)
            self.loweryellowb = helpers.MakeComboEntry(colorsettingsFrame, &#34;Lower B:&#34;, &#34;TrafficLightDetection&#34;, &#34;loweryellow_b&#34;, 5, 4, labelwidth=13, width=7)
            self.uppergreenr = helpers.MakeComboEntry(colorsettingsFrame, &#34;GREEN:    Upper R:&#34;, &#34;TrafficLightDetection&#34;, &#34;uppergreen_r&#34;, 6, 0, labelwidth=20, width=7)
            self.uppergreeng = helpers.MakeComboEntry(colorsettingsFrame, &#34;Upper G:&#34;, &#34;TrafficLightDetection&#34;, &#34;uppergreen_g&#34;, 6, 2, labelwidth=13, width=7)
            self.uppergreenb = helpers.MakeComboEntry(colorsettingsFrame, &#34;Upper B:&#34;, &#34;TrafficLightDetection&#34;, &#34;uppergreen_b&#34;, 6, 4, labelwidth=13, width=7)
            self.lowergreenr = helpers.MakeComboEntry(colorsettingsFrame, &#34;GREEN:    Lower R:&#34;, &#34;TrafficLightDetection&#34;, &#34;lowergreen_r&#34;, 7, 0, labelwidth=20, width=7)
            self.lowergreeng = helpers.MakeComboEntry(colorsettingsFrame, &#34;Lower G:&#34;, &#34;TrafficLightDetection&#34;, &#34;lowergreen_g&#34;, 7, 2, labelwidth=13, width=7)
            self.lowergreenb = helpers.MakeComboEntry(colorsettingsFrame, &#34;Lower B:&#34;, &#34;TrafficLightDetection&#34;, &#34;lowergreen_b&#34;, 7, 4, labelwidth=13, width=7)
            helpers.MakeButton(colorsettingsFrame, &#34;Save&#34;, command=self.save, row=15, column=0, sticky=&#34;w&#34;)

            helpers.MakeLabel(colorsettingsFrame, &#34;&#34;, 13, 0, columnspan=7)
            helpers.MakeLabel(colorsettingsFrame, &#34;&#34;, 14, 0, columnspan=7)
            helpers.MakeButton(colorsettingsFrame, &#34;Reset&#34;, command=self.resetadvancedcolorstodefault, row=15, column=5)
            helpers.MakeEmptyLine(colorsettingsFrame,12,1)
            helpers.MakeEmptyLine(colorsettingsFrame,13,1)
            helpers.MakeEmptyLine(colorsettingsFrame,14,1)
            helpers.MakeButton(filtersFrame, &#34;Reset&#34;, command=self.resetadvancedfilterstodefault, row=15, column=1, width=20)
            helpers.MakeEmptyLine(filtersFrame,14,1)
            helpers.MakeButton(generalFrame, &#34;Reset Advanced Settings\nto Default\n------------------------------------&#34;, command=self.resetalladvancedsettingstodefault, row=6, column=1, width=32,)
            
        
        def save(self):
            
            try:
                self.upperredr.get()
            except:
                self.upperredr.set(255)
            try:
                self.upperredg.get()
            except:
                self.upperredg.set(110)
            try:
                self.upperredb.get()
            except:
                self.upperredb.set(110)
            try:
                self.lowerredr.get()
            except:
                self.lowerredr.set(200)
            try:
                self.lowerredg.get()
            except:
                self.lowerredg.set(0)
            try:
                self.lowerredb.get()
            except:
                self.lowerredb.set(0)
            try:
                self.upperyellowr.get()
            except:
                self.upperyellowr.set(255)
            try:
                self.upperyellowg.get()
            except:
                self.upperyellowg.set(240)
            try:
                self.upperyellowb.get()
            except:
                self.upperyellowb.set(170)
            try:
                self.loweryellowr.get()
            except:
                self.loweryellowr.set(200)
            try:
                self.loweryellowg.get()
            except:
                self.loweryellowg.set(170)
            try:
                self.loweryellowb.get()
            except:
                self.loweryellowb.set(50)
            try:
                self.uppergreenr.get()
            except:
                self.uppergreenr.set(150)
            try:
                self.uppergreeng.get()
            except:
                self.uppergreeng.set(255)
            try:
                self.uppergreenb.get()
            except:
                self.uppergreenb.set(230)
            try:
                self.lowergreenr.get()
            except:
                self.lowergreenr.set(0)
            try:
                self.lowergreeng.get()
            except:
                self.lowergreeng.set(200)
            try:
                self.lowergreenb.get()
            except:
                self.lowergreenb.set(0)
            if not (0 &lt;= self.upperredr.get() &lt;= 255):
                self.upperredr.set(255)
            if not (0 &lt;= self.upperredg.get() &lt;= 255):
                self.upperredg.set(110)
            if not (0 &lt;= self.upperredb.get() &lt;= 255):
                self.upperredb.set(110)
            if not (0 &lt;= self.lowerredr.get() &lt;= 255):
                self.lowerredr.set(200)  
            if not (0 &lt;= self.lowerredg.get() &lt;= 255):
                self.lowerredg.set(0)
            if not (0 &lt;= self.lowerredb.get() &lt;= 255):
                self.lowerredb.set(0)
            if not (0 &lt;= self.upperyellowr.get() &lt;= 255):
                self.upperyellowr.set(255)
            if not (0 &lt;= self.upperyellowg.get() &lt;= 255):
                self.upperyellowg.set(240)
            if not (0 &lt;= self.upperyellowb.get() &lt;= 255):
                self.upperyellowb.set(170)
            if not (0 &lt;= self.loweryellowr.get() &lt;= 255):
                self.loweryellowr.set(200)
            if not (0 &lt;= self.loweryellowg.get() &lt;= 255):
                self.loweryellowg.set(170)
            if not (0 &lt;= self.loweryellowb.get() &lt;= 255):
                self.loweryellowb.set(50)
            if not (0 &lt;= self.uppergreenr.get() &lt;= 255):
                self.uppergreenr.set(150)
            if not (0 &lt;= self.uppergreeng.get() &lt;= 255):
                self.uppergreeng.set(255)
            if not (0 &lt;= self.uppergreenb.get() &lt;= 255):
                self.uppergreenb.set(230)
            if not (0 &lt;= self.lowergreenr.get() &lt;= 255):
                self.lowergreenr.set(0)
            if not (0 &lt;= self.lowergreeng.get() &lt;= 255):
                self.lowergreeng.set(200)
            if not (0 &lt;= self.lowergreenb.get() &lt;= 255):
                self.lowergreenb.set(0)
            settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;upperred_r&#34;, self.upperredr.get())
            settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;upperred_g&#34;, self.upperredg.get())
            settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;upperred_b&#34;, self.upperredb.get())
            settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;lowerred_r&#34;, self.lowerredr.get())
            settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;lowerred_g&#34;, self.lowerredg.get())
            settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;lowerred_b&#34;, self.lowerredb.get())
            settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;upperyellow_r&#34;, self.upperyellowr.get())
            settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;upperyellow_g&#34;, self.upperyellowg.get())
            settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;upperyellow_b&#34;, self.upperyellowb.get())
            settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;loweryellow_r&#34;, self.loweryellowr.get())
            settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;loweryellow_g&#34;, self.loweryellowg.get())
            settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;loweryellow_b&#34;, self.loweryellowb.get())
            settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;uppergreen_r&#34;, self.uppergreenr.get())
            settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;uppergreen_g&#34;, self.uppergreeng.get())
            settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;uppergreen_b&#34;, self.uppergreenb.get())
            settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;lowergreen_r&#34;, self.lowergreenr.get())
            settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;lowergreen_g&#34;, self.lowergreeng.get())
            settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;lowergreen_b&#34;, self.lowergreenb.get())
            UpdateSettings()

        
        def resetadvancedcolorstodefault(self):
            settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;upperred_r&#34;, 255)
            settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;upperred_g&#34;, 110)
            settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;upperred_b&#34;, 110)
            settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;lowerred_r&#34;, 200)
            settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;lowerred_g&#34;, 0)
            settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;lowerred_b&#34;, 0)
            settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;upperyellow_r&#34;, 255)
            settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;upperyellow_g&#34;, 240)
            settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;upperyellow_b&#34;, 170)
            settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;loweryellow_r&#34;, 200)
            settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;loweryellow_g&#34;, 170)
            settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;loweryellow_b&#34;, 50)
            settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;uppergreen_r&#34;, 150)
            settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;uppergreen_g&#34;, 255)
            settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;uppergreen_b&#34;, 230)
            settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;lowergreen_r&#34;, 0)
            settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;lowergreen_g&#34;, 200)
            settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;lowergreen_b&#34;, 0)
            self.upperredr.set(255)
            self.upperredg.set(110)
            self.upperredb.set(110)
            self.lowerredr.set(200)
            self.lowerredg.set(0)
            self.lowerredb.set(0)
            self.upperyellowr.set(255)
            self.upperyellowg.set(240)
            self.upperyellowb.set(170)
            self.loweryellowr.set(200)
            self.loweryellowg.set(170)
            self.loweryellowb.set(50)
            self.uppergreenr.set(150)
            self.uppergreeng.set(255)
            self.uppergreenb.set(230)
            self.lowergreenr.set(0)
            self.lowergreeng.set(200)
            self.lowergreenb.set(0)
            UpdateSettings()

        def resetadvancedfilterstodefault(self):
            settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;rectsizefilter&#34;, True)
            settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;widthheightratiofilter&#34;, True)
            settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;pixelpercentagefilter&#34;, True)
            settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;otherlightsofffilter&#34;, True)

            settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;minrectsize&#34;, round(screen_width / 240))
            settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;maxrectsize&#34;, round(screen_width / 10))
            self.minrectsizeSlider.set(round(screen_width / 240))
            self.minrectsize.set(round(screen_width / 240))
            self.maxrectsizeSlider.set(round(screen_width / 10))
            self.maxrectsize.set(round(screen_width / 10))
            self.exampleFunction()
            UpdateSettings()

        def resetalladvancedsettingstodefault(self):
            settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;rectsizefilter&#34;, True)
            settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;widthheightratiofilter&#34;, True)
            settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;pixelpercentagefilter&#34;, True)
            settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;otherlightsofffilter&#34;, True)

            settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;minrectsize&#34;, round(screen_width / 240))
            settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;maxrectsize&#34;, round(screen_width / 10))

            settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;upperred_r&#34;, 255)
            settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;upperred_g&#34;, 110)
            settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;upperred_b&#34;, 110)
            settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;lowerred_r&#34;, 200)
            settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;lowerred_g&#34;, 0)
            settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;lowerred_b&#34;, 0)
            settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;upperyellow_r&#34;, 255)
            settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;upperyellow_g&#34;, 240)
            settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;upperyellow_b&#34;, 170)
            settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;loweryellow_r&#34;, 200)
            settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;loweryellow_g&#34;, 170)
            settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;loweryellow_b&#34;, 50)
            settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;uppergreen_r&#34;, 150)
            settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;uppergreen_g&#34;, 255)
            settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;uppergreen_b&#34;, 230)
            settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;lowergreen_r&#34;, 0)
            settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;lowergreen_g&#34;, 200)
            settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;lowergreen_b&#34;, 0)
            self.upperredr.set(255)
            self.upperredg.set(110)
            self.upperredb.set(110)
            self.lowerredr.set(200)
            self.lowerredg.set(0)
            self.lowerredb.set(0)
            self.upperyellowr.set(255)
            self.upperyellowg.set(240)
            self.upperyellowb.set(170)
            self.loweryellowr.set(200)
            self.loweryellowg.set(170)
            self.loweryellowb.set(50)
            self.uppergreenr.set(150)
            self.uppergreeng.set(255)
            self.uppergreenb.set(230)
            self.lowergreenr.set(0)
            self.lowergreeng.set(200)
            self.lowergreenb.set(0)
            self.exampleFunction()
            UpdateSettings()

        def save_and_load_model(self):
            global yolo_model_loaded
            yolo_model_loaded = False
            settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;yolo_model&#34;, self.model_ui)
            loadYOLO()
            UpdateSettings()
        
        def update(self, data): 
            self.root.update()
            
    except Exception as ex:
        print(ex.args)</code></pre>
</details>
</section>
<section>
</section>
<section>
</section>
<section>
<h2 class="section-title" id="header-functions">Functions</h2>
<dl>
<dt id="Euro-Truck-Simulator-2-Lane-Assist.plugins.TrafficLightDetection.main.UpdateSettings"><code class="name flex">
<span>def <span class="ident">UpdateSettings</span></span>(<span>)</span>
</code></dt>
<dd>
<div class="desc"></div>
<details class="source">
<summary>
<span>Expand source code</span>
</summary>
<pre><code class="python">def UpdateSettings():
    global min_rect_size
    global max_rect_size
    global width_height_ratio
    global circlepercent
    global maxcircleoffset
    global circleplusoffset
    global circleminusoffset
    global finalwindow
    global grayscalewindow
    global redyellowgreenwindow
    global anywindowopen
    global automaticwindowsize
    global detectyellowlight
    global performancemode
    global advancedmode
    global windowscale
    global usefullframe
    global yolo_detection
    global yolo_showunconfirmed
    global yolo_model_loaded
    global yolo_model
    global coordinates
    global trafficlights
    global windowwidth
    global windowheight
    global reset_window
    global x1
    global y1
    global x2
    global y2

    global rectsizefilter
    global widthheightratiofilter
    global pixelpercentagefilter
    global otherlightsofffilter
    global urr
    global urg
    global urb
    global lrr
    global lrg
    global lrb
    global uyr
    global uyg
    global uyb
    global lyr
    global lyg
    global lyb
    global ugr
    global ugg
    global ugb
    global lgr
    global lgg
    global lgb
    global lower_red_advanced
    global upper_red_advanced
    global lower_green_advanced
    global upper_green_advanced
    global lower_yellow_advanced
    global upper_yellow_advanced
    
    finalwindow = settings.GetSettings(&#34;TrafficLightDetection&#34;, &#34;finalwindow&#34;, True)
    grayscalewindow = settings.GetSettings(&#34;TrafficLightDetection&#34;, &#34;grayscalewindow&#34;, False)
    redyellowgreenwindow = settings.GetSettings(&#34;TrafficLightDetection&#34;, &#34;redyellowgreenwindow&#34;, False)
    automaticwindowsize = settings.GetSettings(&#34;TrafficLightDetection&#34;, &#34;automaticwindowsize&#34;, True)
    detectyellowlight = settings.GetSettings(&#34;TrafficLightDetection&#34;, &#34;detectyellowlight&#34;, False)
    performancemode = settings.GetSettings(&#34;TrafficLightDetection&#34;, &#34;performancemode&#34;, True)
    advancedmode = settings.GetSettings(&#34;TrafficLightDetection&#34;, &#34;advancedmode&#34;, False)
    usefullframe = settings.GetSettings(&#34;TrafficLightDetection&#34;, &#34;usefullframe&#34;, True)
    windowscale = float(settings.GetSettings(&#34;TrafficLightDetection&#34;, &#34;scale&#34;, 0.5))
    x1 = settings.GetSettings(&#34;TrafficLightDetection&#34;, &#34;x1ofsc&#34;, 0)
    y1 = settings.GetSettings(&#34;TrafficLightDetection&#34;, &#34;y1ofsc&#34;, 0)
    x2 = settings.GetSettings(&#34;TrafficLightDetection&#34;, &#34;x2ofsc&#34;, screen_width-1)
    y2 = settings.GetSettings(&#34;TrafficLightDetection&#34;, &#34;y2ofsc&#34;, round(screen_height/1.5)-1)

    rectsizefilter = settings.GetSettings(&#34;TrafficLightDetection&#34;, &#34;rectsizefilter&#34;, True)
    widthheightratiofilter = settings.GetSettings(&#34;TrafficLightDetection&#34;, &#34;widthheightratiofilter&#34;, True)
    pixelpercentagefilter = settings.GetSettings(&#34;TrafficLightDetection&#34;, &#34;pixelpercentagefilter&#34;, True)
    otherlightsofffilter = settings.GetSettings(&#34;TrafficLightDetection&#34;, &#34;otherlightsofffilter&#34;, True)

    yolo_detection = settings.GetSettings(&#34;TrafficLightDetection&#34;, &#34;yolo_detection&#34;, True)
    yolo_showunconfirmed = settings.GetSettings(&#34;TrafficLightDetection&#34;, &#34;yolo_showunconfirmed&#34;, True)

    coordinates = []
    trafficlights = []

    if automaticwindowsize == True:
        if usefullframe == False:
            windowwidth = x2-x1
            windowheight = y2-y1
        else:
            windowwidth = screen_width
            windowheight = round(screen_height/1.5)
    else:
        windowwidth = settings.GetSettings(&#34;TrafficLightDetection&#34;, &#34;outputwindowwidth&#34;, round(screen_width/2))
        windowheight = settings.GetSettings(&#34;TrafficLightDetection&#34;, &#34;outputwindowheight&#34;, round(screen_height/3))
    
    reset_window = True

    if advancedmode == False:
        min_rect_size = screen_width / 240
        max_rect_size = screen_width / 10
    else:
        min_rect_size = settings.GetSettings(&#34;TrafficLightDetection&#34;, &#34;minrectsize&#34;, round(screen_width / 240))
        max_rect_size = settings.GetSettings(&#34;TrafficLightDetection&#34;, &#34;maxrectsize&#34;, round(screen_width / 10))

    width_height_ratio = 0.2
    circlepercent = 0.785
    maxcircleoffset = 0.15
    circleplusoffset = circlepercent + maxcircleoffset
    circleminusoffset = circlepercent - maxcircleoffset

    if min_rect_size &lt; 8:
        min_rect_size = 8

    if ((finalwindow + grayscalewindow + redyellowgreenwindow) &gt; 0):
        anywindowopen = True
    else:
        anywindowopen = False

    if x2-x1-1 &lt; 0:
        print(&#34;Your Screen Capture Coordinates are invalid because the right X is to the left of the left X (message from TrafficLightDetection)&#34;)
        messagebox.showwarning(title=&#34;TrafficLightDetection&#34;, message=&#34;Your Screen Capture Coordinates are invalid because the right X is to the left of the left X (message from TrafficLightDetection)&#34;)
    if y2-y1-1 &lt; 0:
        print(&#34;Your Screen Capture Coordinates are invalid because the bottom Y is above the top Y (message from TrafficLightDetection)&#34;)
        messagebox.showwarning(title=&#34;TrafficLightDetection&#34;, message=&#34;Your Screen Capture Coordinates are invalid because the bottom Y is above the top Y (message from TrafficLightDetection)&#34;)
    
    urr = settings.GetSettings(&#34;TrafficLightDetection&#34;, &#34;upperred_r&#34;)
    if urr == None or not isinstance(urr, int) or not (0 &lt;= urr &lt;= 255):
        settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;upperred_r&#34;, 255)
        urr = 255
    urg = settings.GetSettings(&#34;TrafficLightDetection&#34;, &#34;upperred_g&#34;)
    if urg == None or not isinstance(urg, int) or not (0 &lt;= urg &lt;= 255):
        settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;upperred_g&#34;, 110)
        urg = 110
    urb = settings.GetSettings(&#34;TrafficLightDetection&#34;, &#34;upperred_b&#34;)
    if urb == None or not isinstance(urb, int) or not (0 &lt;= urb &lt;= 255):
        settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;upperred_b&#34;, 110)
        urb = 110
    lrr = settings.GetSettings(&#34;TrafficLightDetection&#34;, &#34;lowerred_r&#34;)
    if lrr == None or not isinstance(lrr, int) or not (0 &lt;= lrr &lt;= 255):
        settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;lowerred_r&#34;, 200)
        lrr = 200
    lrg = settings.GetSettings(&#34;TrafficLightDetection&#34;, &#34;lowerred_g&#34;)
    if lrg == None or not isinstance(lrg, int) or not (0 &lt;= lrg &lt;= 255):
        settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;lowerred_g&#34;, 0)
        lrg = 0
    lrb = settings.GetSettings(&#34;TrafficLightDetection&#34;, &#34;lowerred_b&#34;)
    if lrb == None or not isinstance(lrb, int) or not (0 &lt;= lrb &lt;= 255):
        settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;lowerred_b&#34;, 0)
        lrb = 0
    uyr = settings.GetSettings(&#34;TrafficLightDetection&#34;, &#34;upperyellow_r&#34;)
    if uyr == None or not isinstance(uyr, int) or not (0 &lt;= uyr &lt;= 255):
        settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;upperyellow_r&#34;, 255)
        uyr = 255
    uyg = settings.GetSettings(&#34;TrafficLightDetection&#34;, &#34;upperyellow_g&#34;)
    if uyg == None or not isinstance(uyg, int) or not (0 &lt;= uyg &lt;= 255):
        settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;upperyellow_g&#34;, 240)
        uyg = 240
    uyb = settings.GetSettings(&#34;TrafficLightDetection&#34;, &#34;upperyellow_b&#34;)
    if uyb == None or not isinstance(uyb, int) or not (0 &lt;= uyb &lt;= 255):
        settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;upperyellow_b&#34;, 170)
        uyb = 170
    lyr = settings.GetSettings(&#34;TrafficLightDetection&#34;, &#34;loweryellow_r&#34;)
    if lyr == None or not isinstance(lyr, int) or not (0 &lt;= lyr &lt;= 255):
        settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;loweryellow_r&#34;, 200)
        lyr = 200
    lyg = settings.GetSettings(&#34;TrafficLightDetection&#34;, &#34;loweryellow_g&#34;)
    if lyg == None or not isinstance(lyg, int) or not (0 &lt;= lyg &lt;= 255):
        settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;loweryellow_g&#34;, 170)
        lyg = 170
    lyb = settings.GetSettings(&#34;TrafficLightDetection&#34;, &#34;loweryellow_b&#34;)
    if lyb == None or not isinstance(lyb, int) or not (0 &lt;= lyb &lt;= 255):
        settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;loweryellow_b&#34;, 50)
        lyb = 50
    ugr = settings.GetSettings(&#34;TrafficLightDetection&#34;, &#34;uppergreen_r&#34;)
    if ugr == None or not isinstance(ugr, int) or not (0 &lt;= ugr &lt;= 255):
        settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;uppergreen_r&#34;, 150)
        ugr = 150
    ugg = settings.GetSettings(&#34;TrafficLightDetection&#34;, &#34;uppergreen_g&#34;)
    if ugg == None or not isinstance(ugg, int) or not (0 &lt;= ugg &lt;= 255):
        settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;uppergreen_g&#34;, 255)
        ugg = 255
    ugb = settings.GetSettings(&#34;TrafficLightDetection&#34;, &#34;uppergreen_b&#34;)
    if ugb == None or not isinstance(ugb, int) or not (0 &lt;= ugb &lt;= 255):
        settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;uppergreen_b&#34;, 230)
        ugb = 230
    lgr = settings.GetSettings(&#34;TrafficLightDetection&#34;, &#34;lowergreen_r&#34;)
    if lgr == None or not isinstance(lgr, int) or not (0 &lt;= lgr &lt;= 255):
        settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;lowergreen_r&#34;, 0)
        lgr = 0
    lgg = settings.GetSettings(&#34;TrafficLightDetection&#34;, &#34;lowergreen_g&#34;)
    if lgg == None or not isinstance(lgg, int) or not (0 &lt;= lgg &lt;= 255):
        settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;lowergreen_g&#34;, 200)
        lgg = 200
    lgb = settings.GetSettings(&#34;TrafficLightDetection&#34;, &#34;lowergreen_b&#34;)
    if lgb == None or not isinstance(lgb, int) or not (0 &lt;= lgb &lt;= 255):
        settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;lowergreen_b&#34;, 0)
        lgb = 0

    upper_red_advanced = np.array([urr, urg, urb])
    lower_red_advanced = np.array([lrr, lrg, lrb])
    upper_yellow_advanced = np.array([uyr, uyg, uyb])
    lower_yellow_advanced = np.array([lyr, lyg, lyb])
    upper_green_advanced = np.array([ugr, ugg, ugb])
    lower_green_advanced = np.array([lgr, lgg, lgb])</code></pre>
</details>
</dd>
<dt id="Euro-Truck-Simulator-2-Lane-Assist.plugins.TrafficLightDetection.main.loadYOLO"><code class="name flex">
<span>def <span class="ident">loadYOLO</span></span>(<span>)</span>
</code></dt>
<dd>
<div class="desc"></div>
<details class="source">
<summary>
<span>Expand source code</span>
</summary>
<pre><code class="python">def loadYOLO():
    global yolo_model_loaded
    global yolo_model
    global yolo_detection
    global yolo_showunconfirmed
    global yolo_model_str
    
    yolo_detection = settings.GetSettings(&#34;TrafficLightDetection&#34;, &#34;yolo_detection&#34;, True)
    yolo_showunconfirmed = settings.GetSettings(&#34;TrafficLightDetection&#34;, &#34;yolo_showunconfirmed&#34;, True)
    yolo_model_str = settings.GetSettings(&#34;TrafficLightDetection&#34;, &#34;yolo_model&#34;, &#34;yolov5n&#34;) # &#39;yolov5n&#39;, &#39;yolov5s&#39;, &#39;yolov5m&#39;, &#39;yolov5l&#39;, &#39;yolov5x&#39;
    if yolo_model_loaded == False:
        print(&#34;\033[92m&#34; + f&#34;Loading the {yolo_model_str} model...&#34; + &#34;\033[0m&#34;)
        try:
            import torch
            torch.hub.set_dir(f&#34;{variables.PATH}plugins\\TrafficLightDetection\\YoloFiles&#34;)
            yolo_model = torch.hub.load(&#34;ultralytics/yolov5&#34;, yolo_model_str)
            print(&#34;\033[92m&#34; + f&#34;Successfully loaded the {yolo_model_str} model!&#34; + &#34;\033[0m&#34;)
        except Exception as e:
            print(&#34;\033[91m&#34; + f&#34;Failed to load the {yolo_model_str} model: &#34; + &#34;\033[0m&#34; + str(e))
        yolo_model_loaded = True</code></pre>
</details>
</dd>
<dt id="Euro-Truck-Simulator-2-Lane-Assist.plugins.TrafficLightDetection.main.onDisable"><code class="name flex">
<span>def <span class="ident">onDisable</span></span>(<span>)</span>
</code></dt>
<dd>
<div class="desc"></div>
<details class="source">
<summary>
<span>Expand source code</span>
</summary>
<pre><code class="python">def onDisable():
    pass</code></pre>
</details>
</dd>
<dt id="Euro-Truck-Simulator-2-Lane-Assist.plugins.TrafficLightDetection.main.onEnable"><code class="name flex">
<span>def <span class="ident">onEnable</span></span>(<span>)</span>
</code></dt>
<dd>
<div class="desc"></div>
<details class="source">
<summary>
<span>Expand source code</span>
</summary>
<pre><code class="python">def onEnable():
    UpdateSettings()
    loadYOLO()
    pass</code></pre>
</details>
</dd>
<dt id="Euro-Truck-Simulator-2-Lane-Assist.plugins.TrafficLightDetection.main.plugin"><code class="name flex">
<span>def <span class="ident">plugin</span></span>(<span>data)</span>
</code></dt>
<dd>
<div class="desc"></div>
<details class="source">
<summary>
<span>Expand source code</span>
</summary>
<pre><code class="python">def plugin(data):
    global coordinates
    global trafficlights
    global reset_window
    
    try:
        frameFull = data[&#34;frameFull&#34;]
        if usefullframe == False and x2-x1 &gt; 0 and y2-y1 &gt; 0:
            frame = frameFull[y1:y1+(y2-y1), x1:x1+(x2-x1)]
        else: 
            frame = frameFull[0:round(screen_height/1.5), 0:screen_width] 
    except:
        return data
    
    if frame is None: return data
    rgb_frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)

    # ALL CASES:

    # True: --- False: advancedmode, performancemode, detectyellowlight
    # True: detectyellowlight --- False: advancedmode, performancemode
    # True: performancemode --- False: advancedmode
    # True: --- False: advancedmode, performancemode, detectyellowlight
    # True: detectyellowlight --- False: advancedmode, performancemode
    # True: performancemode --- False: advancedmode
    # True: advancedmode --- False: performancemode, detectyellowlight
    # True: advancedmode, detectyellowlight --- False: performancemode
    # True: advancedmode, performancemode --- False: 
    # True: advancedmode --- False: performancemode, detectyellowlight
    # True: advancedmode, detectyellowlight --- False: performancemode
    # True: advancedmode, performancemode --- False: 

    last_coordinates = coordinates.copy()
    coordinates = []
    if advancedmode == False:
        if performancemode == False:
            if detectyellowlight == False:
                # True: --- False: advancedmode, performancemode, detectyellowlight
                mask_red = cv2.inRange(rgb_frame, lower_red, upper_red)
                mask_green = cv2.inRange(rgb_frame, lower_green, upper_green)
                filtered_frame_red_yellow_green = cv2.bitwise_or(cv2.bitwise_and(frame, frame, mask=mask_red), cv2.bitwise_and(frame, frame, mask=mask_green))
                filtered_frame_bw = cv2.cvtColor(filtered_frame_red_yellow_green, cv2.COLOR_BGR2GRAY)
                final_frame = frame
                contours, _ = cv2.findContours(cv2.cvtColor(filtered_frame_red_yellow_green, cv2.COLOR_BGR2GRAY), cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
                for contour in contours:
                    x, y, w, h = cv2.boundingRect(contour)
                    if min_rect_size &lt; w and max_rect_size &gt; w and min_rect_size &lt; h and max_rect_size &gt; h:
                        if w / h - 1 &lt; width_height_ratio and w / h - 1 &gt; -width_height_ratio:
                            red_pixel_count = cv2.countNonZero(mask_red[y:y+h, x:x+w])
                            green_pixel_count = cv2.countNonZero(mask_green[y:y+h, x:x+w])
                            total_pixels = w * h
                            red_ratio = red_pixel_count / total_pixels
                            green_ratio = green_pixel_count / total_pixels
                            if green_ratio &lt; circleplusoffset and green_ratio &gt; circleminusoffset and red_ratio &lt; 0.1 or red_ratio &lt; circleplusoffset and red_ratio &gt; circleminusoffset and green_ratio &lt; 0.1:
                                if red_ratio &gt; green_ratio:
                                    colorstr = &#34;Red&#34;
                                    yoffset1 = y+h*2
                                    centerx = round(x + w / 2)
                                    centery1 = round(y + h / 2)+h
                                    centery2 = round(y + h / 2)+h*2
                                elif green_ratio &gt; red_ratio:
                                    colorstr = &#34;Green&#34;
                                    yoffset1 = y-h
                                    centerx = round(x + w / 2)
                                    centery1 = round(y + h / 2)-h
                                    centery2 = round(y + h / 2)-h*2
                                else:
                                    colorstr = &#34;Red&#34;
                                    yoffset1 = y+h*2
                                    centerx = round(x + w / 2)
                                    centery1 = round(y + h / 2)+h
                                    centery2 = round(y + h / 2)+h*2
                                try:
                                    centery1_color = rgb_frame[centery1, centerx]
                                except:
                                    centery1_color = (0,0,0)
                                try:
                                    centery2_color = rgb_frame[centery2, centerx]
                                except:
                                    centery2_color = (0,0,0)
                                r_centery1, g_centery1, b_centery1 = centery1_color
                                r_centery2, g_centery2, b_centery2 = centery2_color
                                if r_centery1 &lt; 100 and g_centery1 &lt; 100 and b_centery1 &lt; 100 and r_centery2 &lt; 100 and g_centery2 &lt; 100 and b_centery2 &lt; 100:
                                    coordinates.append((round(x+w/2),round(yoffset1-h/2),w,h,colorstr))

            else:
                # True: detectyellowlight --- False: advancedmode, performancemode
                mask_red = cv2.inRange(rgb_frame, lower_red, upper_red)
                mask_green = cv2.inRange(rgb_frame, lower_green, upper_green)
                mask_yellow = cv2.inRange(rgb_frame, lower_yellow, upper_yellow)
                combined_mask = cv2.bitwise_or(mask_red, cv2.bitwise_or(mask_green, mask_yellow))
                filtered_frame_red_yellow_green = cv2.bitwise_and(frame, frame, mask=combined_mask)
                filtered_frame_bw = cv2.cvtColor(filtered_frame_red_yellow_green, cv2.COLOR_BGR2GRAY)
                final_frame = frame
                contours, _ = cv2.findContours(cv2.cvtColor(filtered_frame_red_yellow_green, cv2.COLOR_BGR2GRAY), cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
                for contour in contours:
                    x, y, w, h = cv2.boundingRect(contour)
                    if min_rect_size &lt; w and max_rect_size &gt; w and min_rect_size &lt; h and max_rect_size &gt; h:
                        if w / h - 1 &lt; width_height_ratio and w / h - 1 &gt; -width_height_ratio:
                            red_pixel_count = cv2.countNonZero(mask_red[y:y+h, x:x+w])
                            green_pixel_count = cv2.countNonZero(mask_green[y:y+h, x:x+w])
                            yellow_pixel_count = cv2.countNonZero(mask_yellow[y:y+h, x:x+w])
                            total_pixels = w * h
                            red_ratio = red_pixel_count / total_pixels
                            green_ratio = green_pixel_count / total_pixels
                            yellow_ratio = yellow_pixel_count / total_pixels
                            if (green_ratio &lt; circleplusoffset and green_ratio &gt; circleminusoffset and red_ratio &lt; 0.1 and yellow_ratio &lt; 0.1 or 
                                red_ratio &lt; circleplusoffset and red_ratio &gt; circleminusoffset and green_ratio &lt; 0.1 and yellow_ratio &lt; 0.1 or 
                                yellow_ratio &lt; circleplusoffset and yellow_ratio &gt; circleminusoffset and green_ratio &lt; 0.1 and red_ratio &lt; 0.1):
                                if red_ratio &gt; green_ratio and red_ratio &gt; yellow_ratio:
                                    colorstr = &#34;Red&#34;
                                    yoffset1 = y+h*2
                                    centerx = round(x + w / 2)
                                    centery1 = round(y + h / 2)+h
                                    centery2 = round(y + h / 2)+h*2
                                elif yellow_ratio &gt; red_ratio and yellow_ratio &gt; green_ratio:
                                    colorstr = &#34;Yellow&#34;
                                    yoffset1 = y+h
                                    centerx = round(x + w / 2)
                                    centery1 = round(y + h / 2)-h
                                    centery2 = round(y + h / 2)+h
                                elif green_ratio &gt; red_ratio and green_ratio &gt; yellow_ratio:
                                    colorstr = &#34;Green&#34;
                                    yoffset1 = y-h
                                    centerx = round(x + w / 2)
                                    centery1 = round(y + h / 2)-h
                                    centery2 = round(y + h / 2)-h*2
                                else:
                                    colorstr = &#34;Red&#34;
                                    yoffset1 = y+h*2
                                    centerx = round(x + w / 2)
                                    centery1 = round(y + h / 2)+h
                                    centery2 = round(y + h / 2)+h*2
                                try:
                                    centery1_color = rgb_frame[centery1, centerx]
                                except:
                                    centery1_color = (0,0,0)
                                try:
                                    centery2_color = rgb_frame[centery2, centerx]
                                except:
                                    centery2_color = (0,0,0)
                                r_centery1, g_centery1, b_centery1 = centery1_color
                                r_centery2, g_centery2, b_centery2 = centery2_color
                                if r_centery1 &lt; 100 and g_centery1 &lt; 100 and b_centery1 &lt; 100 and r_centery2 &lt; 100 and g_centery2 &lt; 100 and b_centery2 &lt; 100:
                                    coordinates.append((round(x+w/2),round(yoffset1-h/2),w,h,colorstr))
                
        else:
            # True: performancemode --- False: advancedmode
            mask_red = cv2.inRange(rgb_frame, lower_red, upper_red)
            filtered_frame_red_yellow_green = cv2.bitwise_and(frame, frame, mask=mask_red)
            filtered_frame_bw = mask_red.copy()
            final_frame = frame
            contours, _ = cv2.findContours(mask_red, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
            for contour in contours:
                x, y, w, h = cv2.boundingRect(contour)
                if min_rect_size &lt; w and max_rect_size &gt; w and min_rect_size &lt; h and max_rect_size &gt; h:
                    if w / h - 1 &lt; width_height_ratio and w / h - 1 &gt; -width_height_ratio:
                        red_pixel_count = cv2.countNonZero(mask_red[y:y+h, x:x+w])
                        total_pixels = w * h
                        red_ratio = red_pixel_count / total_pixels
                        if red_ratio &lt; circleplusoffset and red_ratio &gt; circleminusoffset:
                            colorstr = &#34;Red&#34;
                            yoffset1 = y+h*2
                            centerx = round(x + w / 2)
                            centery1 = round(y + h / 2)+h
                            centery2 = round(y + h / 2)+h*2
                            try:
                                centery1_color = rgb_frame[centery1, centerx]
                            except:
                                centery1_color = (0,0,0)
                            try:
                                centery2_color = rgb_frame[centery2, centerx]
                            except:
                                centery2_color = (0,0,0)
                            r_centery1, g_centery1, b_centery1 = centery1_color
                            r_centery2, g_centery2, b_centery2 = centery2_color
                            if r_centery1 &lt; 100 and g_centery1 &lt; 100 and b_centery1 &lt; 100 and r_centery2 &lt; 100 and g_centery2 &lt; 100 and b_centery2 &lt; 100:
                                coordinates.append((round(x+w/2),round(yoffset1-h/2),w,h,colorstr))

    else:

        if performancemode == False:
            if detectyellowlight == False:
                # True: advancedmode --- False: performancemode, detectyellowlight
                mask_red = cv2.inRange(rgb_frame, lower_red_advanced, upper_red_advanced)
                mask_green = cv2.inRange(rgb_frame, lower_green_advanced, upper_green_advanced)
                filtered_frame_red_yellow_green = cv2.bitwise_or(cv2.bitwise_and(frame, frame, mask=mask_red), cv2.bitwise_and(frame, frame, mask=mask_green))
                filtered_frame_bw = cv2.cvtColor(filtered_frame_red_yellow_green, cv2.COLOR_BGR2GRAY)
                final_frame = frame
                contours, _ = cv2.findContours(cv2.cvtColor(filtered_frame_red_yellow_green, cv2.COLOR_BGR2GRAY), cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
                for contour in contours:
                    x, y, w, h = cv2.boundingRect(contour)
                    istrue = False
                    if rectsizefilter == True:
                        if min_rect_size &lt; w and max_rect_size &gt; w and min_rect_size &lt; h and max_rect_size &gt; h:
                            istrue = True
                    else:
                        istrue = True
                    if istrue == True:
                        istrue = False
                        if widthheightratiofilter == True:
                            if w / h - 1 &lt; width_height_ratio and w / h - 1 &gt; -width_height_ratio:
                                istrue = True
                        else:
                            istrue = True
                        if istrue == True:
                            red_pixel_count = cv2.countNonZero(mask_red[y:y+h, x:x+w])
                            green_pixel_count = cv2.countNonZero(mask_green[y:y+h, x:x+w])
                            total_pixels = w * h
                            red_ratio = red_pixel_count / total_pixels
                            green_ratio = green_pixel_count / total_pixels
                            istrue = False
                            if pixelpercentagefilter == True:
                                if green_ratio &lt; circleplusoffset and green_ratio &gt; circleminusoffset and red_ratio &lt; 0.1 or red_ratio &lt; circleplusoffset and red_ratio &gt; circleminusoffset and green_ratio &lt; 0.1:
                                    istrue = True
                            else:
                                istrue = True
                            if istrue == True:
                                if red_ratio &gt; green_ratio:
                                    colorstr = &#34;Red&#34;
                                    yoffset1 = y+h*2
                                    centerx = round(x + w / 2)
                                    centery1 = round(y + h / 2)+h
                                    centery2 = round(y + h / 2)+h*2
                                elif green_ratio &gt; red_ratio:
                                    colorstr = &#34;Green&#34;
                                    yoffset1 = y-h
                                    centerx = round(x + w / 2)
                                    centery1 = round(y + h / 2)-h
                                    centery2 = round(y + h / 2)-h*2
                                else:
                                    colorstr = &#34;Red&#34;
                                    yoffset1 = y+h*2
                                    centerx = round(x + w / 2)
                                    centery1 = round(y + h / 2)+h
                                    centery2 = round(y + h / 2)+h*2
                                try:
                                    centery1_color = rgb_frame[centery1, centerx]
                                except:
                                    centery1_color = (0,0,0)
                                try:
                                    centery2_color = rgb_frame[centery2, centerx]
                                except:
                                    centery2_color = (0,0,0)
                                r_centery1, g_centery1, b_centery1 = centery1_color
                                r_centery2, g_centery2, b_centery2 = centery2_color
                                istrue = False
                                if otherlightsofffilter == True:
                                    if r_centery1 &lt; 100 and g_centery1 &lt; 100 and b_centery1 &lt; 100 and r_centery2 &lt; 100 and g_centery2 &lt; 100 and b_centery2 &lt; 100:
                                        istrue = True
                                else:
                                    istrue = True
                                if istrue == True:
                                    coordinates.append((round(x+w/2),round(yoffset1-h/2),w,h,colorstr))

            else:
                # True: advancedmode, detectyellowlight --- False: performancemode
                mask_red = cv2.inRange(rgb_frame, lower_red_advanced, upper_red_advanced)
                mask_green = cv2.inRange(rgb_frame, lower_green_advanced, upper_green_advanced)
                mask_yellow = cv2.inRange(rgb_frame, lower_yellow_advanced, upper_yellow_advanced)
                combined_mask = cv2.bitwise_or(mask_red, cv2.bitwise_or(mask_green, mask_yellow))
                filtered_frame_red_yellow_green = cv2.bitwise_and(frame, frame, mask=combined_mask)
                filtered_frame_bw = cv2.cvtColor(filtered_frame_red_yellow_green, cv2.COLOR_BGR2GRAY)
                final_frame = frame
                contours, _ = cv2.findContours(cv2.cvtColor(filtered_frame_red_yellow_green, cv2.COLOR_BGR2GRAY), cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
                for contour in contours:
                    x, y, w, h = cv2.boundingRect(contour)
                    istrue = False
                    if rectsizefilter == True:
                        if min_rect_size &lt; w and max_rect_size &gt; w and min_rect_size &lt; h and max_rect_size &gt; h:
                            istrue = True
                    else:
                        istrue = True
                    if istrue == True:
                        istrue = False
                        if widthheightratiofilter == True:
                            if w / h - 1 &lt; width_height_ratio and w / h - 1 &gt; -width_height_ratio:
                                istrue = True
                        else:
                            istrue = True
                        if istrue == True:
                            red_pixel_count = cv2.countNonZero(mask_red[y:y+h, x:x+w])
                            green_pixel_count = cv2.countNonZero(mask_green[y:y+h, x:x+w])
                            yellow_pixel_count = cv2.countNonZero(mask_yellow[y:y+h, x:x+w])
                            total_pixels = w * h
                            red_ratio = red_pixel_count / total_pixels
                            green_ratio = green_pixel_count / total_pixels
                            yellow_ratio = yellow_pixel_count / total_pixels
                            istrue = False
                            if pixelpercentagefilter == True:
                                if (green_ratio &lt; circleplusoffset and green_ratio &gt; circleminusoffset and red_ratio &lt; 0.1 and yellow_ratio &lt; 0.1 or 
                                    red_ratio &lt; circleplusoffset and red_ratio &gt; circleminusoffset and green_ratio &lt; 0.1 and yellow_ratio &lt; 0.1 or 
                                    yellow_ratio &lt; circleplusoffset and yellow_ratio &gt; circleminusoffset and green_ratio &lt; 0.1 and red_ratio &lt; 0.1):
                                    istrue = True
                            else:
                                istrue = True
                            if istrue == True:
                                if red_ratio &gt; green_ratio and red_ratio &gt; yellow_ratio:
                                    colorstr = &#34;Red&#34;
                                    yoffset1 = y+h*2
                                    centerx = round(x + w / 2)
                                    centery1 = round(y + h / 2)+h
                                    centery2 = round(y + h / 2)+h*2
                                elif yellow_ratio &gt; red_ratio and yellow_ratio &gt; green_ratio:
                                    colorstr = &#34;Yellow&#34;
                                    yoffset1 = y+h
                                    centerx = round(x + w / 2)
                                    centery1 = round(y + h / 2)-h
                                    centery2 = round(y + h / 2)+h
                                elif green_ratio &gt; red_ratio and green_ratio &gt; yellow_ratio:
                                    colorstr = &#34;Green&#34;
                                    yoffset1 = y-h
                                    centerx = round(x + w / 2)
                                    centery1 = round(y + h / 2)-h
                                    centery2 = round(y + h / 2)-h*2
                                else:
                                    colorstr = &#34;Red&#34;
                                    yoffset1 = y+h*2
                                    centerx = round(x + w / 2)
                                    centery1 = round(y + h / 2)+h
                                    centery2 = round(y + h / 2)+h*2
                                try:
                                    centery1_color = rgb_frame[centery1, centerx]
                                except:
                                    centery1_color = (0,0,0)
                                try:
                                    centery2_color = rgb_frame[centery2, centerx]
                                except:
                                    centery2_color = (0,0,0)
                                r_centery1, g_centery1, b_centery1 = centery1_color
                                r_centery2, g_centery2, b_centery2 = centery2_color
                                istrue = False
                                if otherlightsofffilter == True:
                                    if r_centery1 &lt; 100 and g_centery1 &lt; 100 and b_centery1 &lt; 100 and r_centery2 &lt; 100 and g_centery2 &lt; 100 and b_centery2 &lt; 100:
                                        istrue = True
                                else:
                                    istrue = True
                                if istrue == True:
                                    coordinates.append((round(x+w/2),round(yoffset1-h/2),w,h,colorstr))
                    
        else:
            # True: advancedmode, performancemode --- False:     
            mask_red = cv2.inRange(rgb_frame, lower_red_advanced, upper_red_advanced)
            filtered_frame_red_yellow_green = cv2.bitwise_and(frame, frame, mask=mask_red)
            filtered_frame_bw = mask_red.copy()
            final_frame = frame
            contours, _ = cv2.findContours(mask_red, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
            for contour in contours:
                x, y, w, h = cv2.boundingRect(contour)
                istrue = False
                if rectsizefilter == True:
                    if min_rect_size &lt; w and max_rect_size &gt; w and min_rect_size &lt; h and max_rect_size &gt; h:
                        istrue = True
                else:
                    istrue = True
                if istrue == True:
                    istrue = False
                    if widthheightratiofilter == True:
                        if w / h - 1 &lt; width_height_ratio and w / h - 1 &gt; -width_height_ratio:
                            istrue = True
                    else:
                        istrue = True
                    if istrue == True:
                        red_pixel_count = cv2.countNonZero(mask_red[y:y+h, x:x+w])
                        total_pixels = w * h
                        red_ratio = red_pixel_count / total_pixels
                        istrue = False
                        if pixelpercentagefilter == True:
                            if red_ratio &lt; circleplusoffset and red_ratio &gt; circleminusoffset:
                                istrue = True
                        else:
                            istrue = True
                        if istrue == True:
                            colorstr = &#34;Red&#34;
                            yoffset1 = y+h*2
                            centerx = round(x + w / 2)
                            centery1 = round(y + h / 2)+h
                            centery2 = round(y + h / 2)+h*2
                            try:
                                centery1_color = rgb_frame[centery1, centerx]
                            except:
                                centery1_color = (0,0,0)
                            try:
                                centery2_color = rgb_frame[centery2, centerx]
                            except:
                                centery2_color = (0,0,0)
                            r_centery1, g_centery1, b_centery1 = centery1_color
                            r_centery2, g_centery2, b_centery2 = centery2_color
                            istrue = False
                            if otherlightsofffilter == True:
                                if r_centery1 &lt; 100 and g_centery1 &lt; 100 and b_centery1 &lt; 100 and r_centery2 &lt; 100 and g_centery2 &lt; 100 and b_centery2 &lt; 100:
                                    istrue = True
                            else:
                                istrue = True
                            if istrue == True:
                                coordinates.append((round(x+w/2),round(yoffset1-h/2),w,h,colorstr))

    if yolo_detection == True:
        try:
            # Tracking with IDs:

            def generate_new_id():
                used_ids = set(id for _, id, _ in trafficlights)
                new_id = 1
                while new_id in used_ids:
                    new_id += 1
                return new_id

            if last_coordinates:
                for i in range(len(last_coordinates)):
                    last_x, last_y, w, h, state = last_coordinates[i]
                    closest = screen_width
                    nearestpoint = None
                    exists_in_trafficlights = False
                    saved_id = None
                    saved_approved = None
                    for j in range(len(coordinates)):
                        x, y, w, h, state = coordinates[j]
                        distance = math.sqrt((x - last_x)**2 + (y - last_y)**2)
                        if distance &lt; closest:
                            closest = distance
                            nearestpoint = x, y, w, h, state

                    # Remove missing points from traffic lights and update list
                    if nearestpoint:
                        for k, (coord, id, approved) in enumerate(trafficlights):
                            if coord == last_coordinates[i]:
                                exists_in_trafficlights = True
                                saved_id = id
                                saved_approved = approved
                                del trafficlights[k]
                                break
                        if exists_in_trafficlights:
                            trafficlights.append((nearestpoint, saved_id, saved_approved))
                        else:
                            new_id = generate_new_id()
                            x, y, w, h, state = nearestpoint
                            x1_confirmation = round(x - w*6)
                            y1_confirmation = round(y - w*7)
                            x2_confirmation = round(x + w*6)
                            y2_confirmation = round(y + w*7)
                            if x1_confirmation &lt; 0:
                                x1_confirmation = 0
                            if y1_confirmation &lt; 0:
                                y1_confirmation = 0
                            if x2_confirmation &gt; screen_width - 1:
                                x2_confirmation = screen_width - 1
                            if y2_confirmation &gt; screen_height - 1:
                                y2_confirmation = screen_height - 1
                            if usefullframe == False and x2-x1 &gt; 0 and y2-y1 &gt; 0:
                                yolo_detection_frame = frameFull[y1+y1_confirmation:y1+y2_confirmation, x1+x1_confirmation:x1+x2_confirmation]
                            else:
                                yolo_detection_frame = frameFull[y1_confirmation:y2_confirmation, x1_confirmation:x2_confirmation]
                            approved = yolo_detection_function(yolo_detection_frame, x, y, w, h)
                            trafficlights.append((nearestpoint, new_id, approved))

                # Remove lost traffic lights based on distance traveled
                lost_trafficlights = len(last_coordinates) - len(coordinates)
                if lost_trafficlights &gt; 0:
                    max_distances = []
                    for i, ((x, y, w, h, state), _, _) in enumerate(trafficlights):
                        if i &lt; len(last_coordinates):
                            distance = math.sqrt((x - last_coordinates[i][0])**2 + (y - last_coordinates[i][1])**2)
                            max_distances.append((distance, i))
                    max_distances.sort(reverse=True)
                    for _ in range(lost_trafficlights):
                        if max_distances:
                            max_index = max_distances.pop(0)[1]
                            del trafficlights[max_index]

                # Filter to remove extra IDs
                if len(trafficlights) &gt; len(coordinates):
                    id_counts = {}
                    for _, id, _ in trafficlights:
                        id_counts[id] = id_counts.get(id, 0) + 1

                    for _ in range(len(trafficlights) - len(coordinates)):
                        max_index = None
                        max_count = 0
                        for i, (_, id, _) in enumerate(trafficlights):
                            if id_counts[id] &gt; max_count:
                                max_index = i
                                max_count = id_counts[id]

                        if max_index is not None:
                            del trafficlights[max_index]
                            id_counts[trafficlights[max_index][1]] -= 1

                
            if anywindowopen == True:
                for i in range(len(trafficlights)):
                    coord, id, approved = trafficlights[i]
                    x, y, w, h, state = coord
                    radius = round((w+h)/4)
                    thickness = round((w+h)/30)
                    if thickness &lt; 1:
                        thickness = 1
                    if approved == True:
                        if state == &#34;Red&#34;:
                            color = (0, 0, 255)
                            cv2.circle(final_frame, (x,y-h), radius, color, thickness)
                            cv2.circle(filtered_frame_bw, (x,y-h), radius, (255, 255, 255), thickness)
                            cv2.circle(filtered_frame_red_yellow_green, (x,y-h), radius,color, thickness)
                            cv2.rectangle(final_frame, (x-w, y-h*2), (x+w, y+h*2), color, radius)
                            cv2.rectangle(filtered_frame_red_yellow_green, (x-w, y-h*2), (x+w, y+h*2), color, radius)
                            if grayscalewindow == True:
                                cv2.rectangle(filtered_frame_bw, (x-round(w/2), y-round(h*1.5)), (x+round(w/2), y-round(h/2)), (150, 150, 150), thickness)
                            if redyellowgreenwindow == True:
                                cv2.rectangle(filtered_frame_red_yellow_green, (x-round(w/2), y-round(h*1.5)), (x+round(w/2), y-round(h/2)), (150, 150, 150), thickness)
                                cv2.rectangle(filtered_frame_red_yellow_green, (x-round(w/2), y-round(h/2)), (x+round(w/2), y+round(h/2)), (150, 150, 150), thickness)
                                cv2.rectangle(filtered_frame_red_yellow_green, (x-round(w/2), y+round(h/2)), (x+round(w/2), y+round(h*1.5)), (150, 150, 150), thickness)
                            if finalwindow == True:
                                cv2.rectangle(final_frame, (x-round(w/2), y-round(h*1.5)), (x+round(w/2), y-round(h/2)), (150, 150, 150), thickness)
                                cv2.rectangle(final_frame, (x-round(w/2), y-round(h/2)), (x+round(w/2), y+round(h/2)), (150, 150, 150), thickness)
                                cv2.rectangle(final_frame, (x-round(w/2), y+round(h/2)), (x+round(w/2), y+round(h*1.5)), (150, 150, 150), thickness)
                        if state == &#34;Yellow&#34;:
                            color = (0, 255, 255)
                            cv2.circle(final_frame, (x,y), radius, color, thickness)
                            cv2.circle(filtered_frame_bw, (x,y), radius, (255, 255, 255), thickness)
                            cv2.circle(filtered_frame_red_yellow_green, (x,y), radius,color, thickness)
                            cv2.rectangle(final_frame, (x-w, y-h*2), (x+w, y+h*2), color, radius)
                            cv2.rectangle(filtered_frame_red_yellow_green, (x-w, y-h*2), (x+w, y+h*2), color, radius)
                            if grayscalewindow == True:
                                cv2.rectangle(filtered_frame_bw, (x-round(w/2), y-round(h/2)), (x+round(w/2), y+round(h/2)), (150, 150, 150), thickness)
                            if redyellowgreenwindow == True:
                                cv2.rectangle(filtered_frame_red_yellow_green, (x-round(w/2), y-round(h*1.5)), (x+round(w/2), y-round(h/2)), (150, 150, 150), thickness)
                                cv2.rectangle(filtered_frame_red_yellow_green, (x-round(w/2), y-round(h/2)), (x+round(w/2), y+round(h/2)), (150, 150, 150), thickness)
                                cv2.rectangle(filtered_frame_red_yellow_green, (x-round(w/2), y+round(h/2)), (x+round(w/2), y+round(h*1.5)), (150, 150, 150), thickness)
                            if finalwindow == True:
                                cv2.rectangle(final_frame, (x-round(w/2), y-round(h*1.5)), (x+round(w/2), y-round(h/2)), (150, 150, 150), thickness)
                                cv2.rectangle(final_frame, (x-round(w/2), y-round(h/2)), (x+round(w/2), y+round(h/2)), (150, 150, 150), thickness)
                                cv2.rectangle(final_frame, (x-round(w/2), y+round(h/2)), (x+round(w/2), y+round(h*1.5)), (150, 150, 150), thickness)
                        if state == &#34;Green&#34;:
                            color = (0, 255, 0)
                            cv2.circle(final_frame, (x,y+h*2), radius, color, thickness)
                            cv2.circle(filtered_frame_bw, (x,y+h*2), radius, (255, 255, 255), thickness)
                            cv2.circle(filtered_frame_red_yellow_green, (x,y+h*2), radius,color, thickness)
                            cv2.rectangle(final_frame, (x-w, y-h), (x+w, y+h*3), color, radius)
                            cv2.rectangle(filtered_frame_red_yellow_green, (x-w, y-h), (x+w, y+h*3), color, radius)
                            if grayscalewindow == True:
                                cv2.rectangle(filtered_frame_bw, (x-round(w/2), y+round(h*1.5)), (x+round(w/2), y+round(h*2.5)), (150, 150, 150), thickness)
                            if redyellowgreenwindow == True:
                                cv2.rectangle(filtered_frame_red_yellow_green, (x-round(w/2), y-round(h/2)), (x+round(w/2), y+round(h/2)), (150, 150, 150), thickness)
                                cv2.rectangle(filtered_frame_red_yellow_green, (x-round(w/2), y+round(h/2)), (x+round(w/2), y+round(h*1.5)), (150, 150, 150), thickness)
                                cv2.rectangle(filtered_frame_red_yellow_green, (x-round(w/2), y+round(h*1.5)), (x+round(w/2), y+round(h*2.5)), (150, 150, 150), thickness)
                            if finalwindow == True:
                                cv2.rectangle(final_frame, (x-round(w/2), y-round(h/2)), (x+round(w/2), y+round(h/2)), (150, 150, 150), thickness)
                                cv2.rectangle(final_frame, (x-round(w/2), y+round(h/2)), (x+round(w/2), y+round(h*1.5)), (150, 150, 150), thickness)
                                cv2.rectangle(final_frame, (x-round(w/2), y+round(h*1.5)), (x+round(w/2), y+round(h*2.5)), (150, 150, 150), thickness)
                    elif approved == False and yolo_showunconfirmed == True:
                        if state == &#34;Red&#34;:
                            color = (150, 150, 150)
                            cv2.circle(final_frame, (x,y-h), radius, color, thickness)
                            cv2.circle(filtered_frame_bw, (x,y-h), radius, (255, 255, 255), thickness)
                            cv2.circle(filtered_frame_red_yellow_green, (x,y-h), radius,color, thickness)
                            cv2.rectangle(final_frame, (x-w, y-h*2), (x+w, y+h*2), color, radius)
                            cv2.rectangle(filtered_frame_red_yellow_green, (x-w, y-h*2), (x+w, y+h*2), color, radius)
                            if grayscalewindow == True:
                                cv2.rectangle(filtered_frame_bw, (x-round(w/2), y-round(h*1.5)), (x+round(w/2), y-round(h/2)), (150, 150, 150), thickness)
                            if redyellowgreenwindow == True:
                                cv2.rectangle(filtered_frame_red_yellow_green, (x-round(w/2), y-round(h*1.5)), (x+round(w/2), y-round(h/2)), (150, 150, 150), thickness)
                                cv2.rectangle(filtered_frame_red_yellow_green, (x-round(w/2), y-round(h/2)), (x+round(w/2), y+round(h/2)), (150, 150, 150), thickness)
                                cv2.rectangle(filtered_frame_red_yellow_green, (x-round(w/2), y+round(h/2)), (x+round(w/2), y+round(h*1.5)), (150, 150, 150), thickness)
                            if finalwindow == True:
                                cv2.rectangle(final_frame, (x-round(w/2), y-round(h*1.5)), (x+round(w/2), y-round(h/2)), (150, 150, 150), thickness)
                                cv2.rectangle(final_frame, (x-round(w/2), y-round(h/2)), (x+round(w/2), y+round(h/2)), (150, 150, 150), thickness)
                                cv2.rectangle(final_frame, (x-round(w/2), y+round(h/2)), (x+round(w/2), y+round(h*1.5)), (150, 150, 150), thickness)
                        if state == &#34;Yellow&#34;:
                            color = (150, 150, 150)
                            cv2.circle(final_frame, (x,y), radius, color, thickness)
                            cv2.circle(filtered_frame_bw, (x,y), radius, (255, 255, 255), thickness)
                            cv2.circle(filtered_frame_red_yellow_green, (x,y), radius,color, thickness)
                            cv2.rectangle(final_frame, (x-w, y-h*2), (x+w, y+h*2), color, radius)
                            cv2.rectangle(filtered_frame_red_yellow_green, (x-w, y-h*2), (x+w, y+h*2), color, radius)
                            if grayscalewindow == True:
                                cv2.rectangle(filtered_frame_bw, (x-round(w/2), y-round(h/2)), (x+round(w/2), y+round(h/2)), (150, 150, 150), thickness)
                            if redyellowgreenwindow == True:
                                cv2.rectangle(filtered_frame_red_yellow_green, (x-round(w/2), y-round(h*1.5)), (x+round(w/2), y-round(h/2)), (150, 150, 150), thickness)
                                cv2.rectangle(filtered_frame_red_yellow_green, (x-round(w/2), y-round(h/2)), (x+round(w/2), y+round(h/2)), (150, 150, 150), thickness)
                                cv2.rectangle(filtered_frame_red_yellow_green, (x-round(w/2), y+round(h/2)), (x+round(w/2), y+round(h*1.5)), (150, 150, 150), thickness)
                            if finalwindow == True:
                                cv2.rectangle(final_frame, (x-round(w/2), y-round(h*1.5)), (x+round(w/2), y-round(h/2)), (150, 150, 150), thickness)
                                cv2.rectangle(final_frame, (x-round(w/2), y-round(h/2)), (x+round(w/2), y+round(h/2)), (150, 150, 150), thickness)
                                cv2.rectangle(final_frame, (x-round(w/2), y+round(h/2)), (x+round(w/2), y+round(h*1.5)), (150, 150, 150), thickness)
                        if state == &#34;Green&#34;:
                            color = (150, 150, 150)
                            cv2.circle(final_frame, (x,y+h*2), radius, color, thickness)
                            cv2.circle(filtered_frame_bw, (x,y+h*2), radius, (255, 255, 255), thickness)
                            cv2.circle(filtered_frame_red_yellow_green, (x,y+h*2), radius,color, thickness)
                            cv2.rectangle(final_frame, (x-w, y-h), (x+w, y+h*3), color, radius)
                            cv2.rectangle(filtered_frame_red_yellow_green, (x-w, y-h), (x+w, y+h*3), color, radius)
                            if grayscalewindow == True:
                                cv2.rectangle(filtered_frame_bw, (x-round(w/2), y+round(h*1.5)), (x+round(w/2), y+round(h*2.5)), (150, 150, 150), thickness)
                            if redyellowgreenwindow == True:
                                cv2.rectangle(filtered_frame_red_yellow_green, (x-round(w/2), y-round(h/2)), (x+round(w/2), y+round(h/2)), (150, 150, 150), thickness)
                                cv2.rectangle(filtered_frame_red_yellow_green, (x-round(w/2), y+round(h/2)), (x+round(w/2), y+round(h*1.5)), (150, 150, 150), thickness)
                                cv2.rectangle(filtered_frame_red_yellow_green, (x-round(w/2), y+round(h*1.5)), (x+round(w/2), y+round(h*2.5)), (150, 150, 150), thickness)
                            if finalwindow == True:
                                cv2.rectangle(final_frame, (x-round(w/2), y-round(h/2)), (x+round(w/2), y+round(h/2)), (150, 150, 150), thickness)
                                cv2.rectangle(final_frame, (x-round(w/2), y+round(h/2)), (x+round(w/2), y+round(h*1.5)), (150, 150, 150), thickness)
                                cv2.rectangle(final_frame, (x-round(w/2), y+round(h*1.5)), (x+round(w/2), y+round(h*2.5)), (150, 150, 150), thickness)

        except Exception as e:
            print(&#34;TrafficLightDetection - Tracking/YOLO Error: &#34; + str(e))
    else:
        if anywindowopen == True:
            for i in range(len(coordinates)):
                x, y, w, h, state = coordinates[i]
                radius = round((w+h)/4)
                thickness = round((w+h)/30)
                if thickness &lt; 1:
                    thickness = 1
                if state == &#34;Red&#34;:
                    color = (0, 0, 255)
                    cv2.circle(final_frame, (x,y-h), radius, color, thickness)
                    cv2.circle(filtered_frame_bw, (x,y-h), radius, (255, 255, 255), thickness)
                    cv2.circle(filtered_frame_red_yellow_green, (x,y-h), radius,color, thickness)
                    cv2.rectangle(final_frame, (x-w, y-h*2), (x+w, y+h*2), color, radius)
                    cv2.rectangle(filtered_frame_red_yellow_green, (x-w, y-h*2), (x+w, y+h*2), color, radius)
                    if grayscalewindow == True:
                        cv2.rectangle(filtered_frame_bw, (x-round(w/2), y-round(h*1.5)), (x+round(w/2), y-round(h/2)), (150, 150, 150), thickness)
                    if redyellowgreenwindow == True:
                        cv2.rectangle(filtered_frame_red_yellow_green, (x-round(w/2), y-round(h*1.5)), (x+round(w/2), y-round(h/2)), (150, 150, 150), thickness)
                        cv2.rectangle(filtered_frame_red_yellow_green, (x-round(w/2), y-round(h/2)), (x+round(w/2), y+round(h/2)), (150, 150, 150), thickness)
                        cv2.rectangle(filtered_frame_red_yellow_green, (x-round(w/2), y+round(h/2)), (x+round(w/2), y+round(h*1.5)), (150, 150, 150), thickness)
                    if finalwindow == True:
                        cv2.rectangle(final_frame, (x-round(w/2), y-round(h*1.5)), (x+round(w/2), y-round(h/2)), (150, 150, 150), thickness)
                        cv2.rectangle(final_frame, (x-round(w/2), y-round(h/2)), (x+round(w/2), y+round(h/2)), (150, 150, 150), thickness)
                        cv2.rectangle(final_frame, (x-round(w/2), y+round(h/2)), (x+round(w/2), y+round(h*1.5)), (150, 150, 150), thickness)
                if state == &#34;Yellow&#34;:
                    color = (0, 255, 255)
                    cv2.circle(final_frame, (x,y), radius, color, thickness)
                    cv2.circle(filtered_frame_bw, (x,y), radius, (255, 255, 255), thickness)
                    cv2.circle(filtered_frame_red_yellow_green, (x,y), radius,color, thickness)
                    cv2.rectangle(final_frame, (x-w, y-h*2), (x+w, y+h*2), color, radius)
                    cv2.rectangle(filtered_frame_red_yellow_green, (x-w, y-h*2), (x+w, y+h*2), color, radius)
                    if grayscalewindow == True:
                        cv2.rectangle(filtered_frame_bw, (x-round(w/2), y-round(h/2)), (x+round(w/2), y+round(h/2)), (150, 150, 150), thickness)
                    if redyellowgreenwindow == True:
                        cv2.rectangle(filtered_frame_red_yellow_green, (x-round(w/2), y-round(h*1.5)), (x+round(w/2), y-round(h/2)), (150, 150, 150), thickness)
                        cv2.rectangle(filtered_frame_red_yellow_green, (x-round(w/2), y-round(h/2)), (x+round(w/2), y+round(h/2)), (150, 150, 150), thickness)
                        cv2.rectangle(filtered_frame_red_yellow_green, (x-round(w/2), y+round(h/2)), (x+round(w/2), y+round(h*1.5)), (150, 150, 150), thickness)
                    if finalwindow == True:
                        cv2.rectangle(final_frame, (x-round(w/2), y-round(h*1.5)), (x+round(w/2), y-round(h/2)), (150, 150, 150), thickness)
                        cv2.rectangle(final_frame, (x-round(w/2), y-round(h/2)), (x+round(w/2), y+round(h/2)), (150, 150, 150), thickness)
                        cv2.rectangle(final_frame, (x-round(w/2), y+round(h/2)), (x+round(w/2), y+round(h*1.5)), (150, 150, 150), thickness)
                if state == &#34;Green&#34;:
                    color = (0, 255, 0)
                    cv2.circle(final_frame, (x,y+h*2), radius, color, thickness)
                    cv2.circle(filtered_frame_bw, (x,y+h*2), radius, (255, 255, 255), thickness)
                    cv2.circle(filtered_frame_red_yellow_green, (x,y+h*2), radius,color, thickness)
                    cv2.rectangle(final_frame, (x-w, y-h), (x+w, y+h*3), color, radius)
                    cv2.rectangle(filtered_frame_red_yellow_green, (x-w, y-h), (x+w, y+h*3), color, radius)
                    if grayscalewindow == True:
                        cv2.rectangle(filtered_frame_bw, (x-round(w/2), y+round(h*1.5)), (x+round(w/2), y+round(h*2.5)), (150, 150, 150), thickness)
                    if redyellowgreenwindow == True:
                        cv2.rectangle(filtered_frame_red_yellow_green, (x-round(w/2), y-round(h/2)), (x+round(w/2), y+round(h/2)), (150, 150, 150), thickness)
                        cv2.rectangle(filtered_frame_red_yellow_green, (x-round(w/2), y+round(h/2)), (x+round(w/2), y+round(h*1.5)), (150, 150, 150), thickness)
                        cv2.rectangle(filtered_frame_red_yellow_green, (x-round(w/2), y+round(h*1.5)), (x+round(w/2), y+round(h*2.5)), (150, 150, 150), thickness)
                    if finalwindow == True:
                        cv2.rectangle(final_frame, (x-round(w/2), y-round(h/2)), (x+round(w/2), y+round(h/2)), (150, 150, 150), thickness)
                        cv2.rectangle(final_frame, (x-round(w/2), y+round(h/2)), (x+round(w/2), y+round(h*1.5)), (150, 150, 150), thickness)
                        cv2.rectangle(final_frame, (x-round(w/2), y+round(h*1.5)), (x+round(w/2), y+round(h*2.5)), (150, 150, 150), thickness)

    try:
        if yolo_detection == True:
            data_simple = None
            for i in range(len(trafficlights)):
                coord, id, approved = trafficlights[i]
                x, y, w, h, state = coord
                if state == &#34;Red&#34; and approved == True:
                    data_simple = &#34;Red&#34;
                    break
                elif state == &#34;Yellow&#34; and approved == True:
                    data_simple = &#34;Yellow&#34;
                    break
                elif state == &#34;Green&#34; and approved == True:
                    data_simple = &#34;Green&#34;
                    break
            data[&#34;TrafficLightDetection&#34;] = {}
            data[&#34;TrafficLightDetection&#34;][&#34;simple&#34;] = data_simple
            data[&#34;TrafficLightDetection&#34;][&#34;detailed&#34;] = trafficlights
        else:
            data_simple = None
            for i in range(len(coordinates)):
                x, y, w, h, state = coordinates[i]
                if state == &#34;Red&#34;:
                    data_simple = &#34;Red&#34;
                    break
                elif state == &#34;Yellow&#34;:
                    data_simple = &#34;Yellow&#34;
                    break
                elif state == &#34;Green&#34;:
                    data_simple = &#34;Green&#34;
                    break
            data[&#34;TrafficLightDetection&#34;] = {}
            data[&#34;TrafficLightDetection&#34;][&#34;simple&#34;] = data_simple
            data[&#34;TrafficLightDetection&#34;][&#34;detailed&#34;] = coordinates
    except Exception as e:
        print(&#34;TrafficLightDetection - Data Error: &#34; + str(e))

    if reset_window == True:
        if grayscalewindow == False:
            try:
                cv2.destroyWindow(&#39;Traffic Light Detection - B/W&#39;)
            except:
                pass
        if redyellowgreenwindow == False:
            try:
                cv2.destroyWindow(&#39;Traffic Light Detection - Red/Yellow/Green&#39;)
            except:
                pass
        if finalwindow == False:
            try:
                cv2.destroyWindow(&#39;Traffic Light Detection - Final&#39;)
            except:
                pass

    if grayscalewindow == True:
        window_handle = ctypes.windll.user32.FindWindowW(None, &#39;Traffic Light Detection - B/W&#39;)
        if window_handle == 0 or reset_window == True:
            cv2.namedWindow(&#39;Traffic Light Detection - B/W&#39;, cv2.WINDOW_NORMAL)
            cv2.resizeWindow(&#39;Traffic Light Detection - B/W&#39;, round(windowwidth*windowscale), round(windowheight*windowscale))
            cv2.setWindowProperty(&#39;Traffic Light Detection - B/W&#39;, cv2.WND_PROP_TOPMOST, 1)
        cv2.imshow(&#39;Traffic Light Detection - B/W&#39;, filtered_frame_bw)
    if redyellowgreenwindow == True:      
        if performancemode == False:
            if detectyellowlight == False:
                window_handle = ctypes.windll.user32.FindWindowW(None, &#39;Traffic Light Detection - Red/Yellow/Green&#39;)
                if window_handle == 0 or reset_window == True:
                    cv2.namedWindow(&#39;Traffic Light Detection - Red/Yellow/Green&#39;, cv2.WINDOW_NORMAL)
                    cv2.resizeWindow(&#39;Traffic Light Detection - Red/Yellow/Green&#39;, round(windowwidth*windowscale), round(windowheight*windowscale))
                    cv2.setWindowProperty(&#39;Traffic Light Detection - Red/Yellow/Green&#39;, cv2.WND_PROP_TOPMOST, 1)
                cv2.imshow(&#39;Traffic Light Detection - Red/Yellow/Green&#39;, filtered_frame_red_yellow_green)
            else:
                window_handle = ctypes.windll.user32.FindWindowW(None, &#39;Traffic Light Detection - Red/Yellow/Green&#39;)
                if window_handle == 0 or reset_window == True:
                    cv2.namedWindow(&#39;Traffic Light Detection - Red/Yellow/Green&#39;, cv2.WINDOW_NORMAL)
                    cv2.resizeWindow(&#39;Traffic Light Detection - Red/Yellow/Green&#39;, round(windowwidth*windowscale), round(windowheight*windowscale))
                    cv2.setWindowProperty(&#39;Traffic Light Detection - Red/Yellow/Green&#39;, cv2.WND_PROP_TOPMOST, 1)
                cv2.imshow(&#39;Traffic Light Detection - Red/Yellow/Green&#39;, filtered_frame_red_yellow_green)
        else:
            window_handle = ctypes.windll.user32.FindWindowW(None, &#39;Traffic Light Detection - Red/Yellow/Green&#39;)
            if window_handle == 0 or reset_window == True:
                cv2.namedWindow(&#39;Traffic Light Detection - Red/Yellow/Green&#39;, cv2.WINDOW_NORMAL)
                cv2.resizeWindow(&#39;Traffic Light Detection - Red/Yellow/Green&#39;, round(windowwidth*windowscale), round(windowheight*windowscale))
                cv2.setWindowProperty(&#39;Traffic Light Detection - Red/Yellow/Green&#39;, cv2.WND_PROP_TOPMOST, 1)
            cv2.imshow(&#39;Traffic Light Detection - Red/Yellow/Green&#39;, filtered_frame_red_yellow_green)
    if finalwindow == True:
        window_handle = ctypes.windll.user32.FindWindowW(None, &#39;Traffic Light Detection - Final&#39;)
        if window_handle == 0 or reset_window == True:
            cv2.namedWindow(&#39;Traffic Light Detection - Final&#39;, cv2.WINDOW_NORMAL)
            cv2.resizeWindow(&#39;Traffic Light Detection - Final&#39;, round(windowwidth*windowscale), round(windowheight*windowscale))
            cv2.setWindowProperty(&#39;Traffic Light Detection - Final&#39;, cv2.WND_PROP_TOPMOST, 1)
        cv2.imshow(&#39;Traffic Light Detection - Final&#39;, final_frame)
    if reset_window == True:
        reset_window = False
    return data # Plugins need to ALWAYS return the data</code></pre>
</details>
</dd>
<dt id="Euro-Truck-Simulator-2-Lane-Assist.plugins.TrafficLightDetection.main.yolo_detection_function"><code class="name flex">
<span>def <span class="ident">yolo_detection_function</span></span>(<span>yolo_detection_frame, x, y, w, h)</span>
</code></dt>
<dd>
<div class="desc"></div>
<details class="source">
<summary>
<span>Expand source code</span>
</summary>
<pre><code class="python">def yolo_detection_function(yolo_detection_frame, x, y, w, h):
    trafficlight = False
    if yolo_model is None or yolo_model_loaded == False:
        loadYOLO()
    results = yolo_model(yolo_detection_frame)
    boxes = results.pandas().xyxy[0]
    for _, box in boxes.iterrows():
        if box[&#39;name&#39;] in [&#39;traffic light&#39;]:
            if (int(box[&#39;xmin&#39;]) &lt; round(yolo_detection_frame.shape[1] / 2) &lt; int(box[&#39;xmax&#39;])) and (int(box[&#39;ymin&#39;]) &lt; round(yolo_detection_frame.shape[0] / 2) &lt; int(box[&#39;ymax&#39;])):
                trafficlight = True
    return trafficlight</code></pre>
</details>
</dd>
</dl>
</section>
<section>
<h2 class="section-title" id="header-classes">Classes</h2>
<dl>
<dt id="Euro-Truck-Simulator-2-Lane-Assist.plugins.TrafficLightDetection.main.UI"><code class="flex name class">
<span>class <span class="ident">UI</span></span>
<span>(</span><span>master)</span>
</code></dt>
<dd>
<div class="desc"></div>
<details class="source">
<summary>
<span>Expand source code</span>
</summary>
<pre><code class="python">class UI():
    try: 
        
        def __init__(self, master) -&gt; None:
            self.master = master 
            self.exampleFunction()
            resizeWindow(850,600)
        
        def destroy(self):
            self.done = True
            self.root.destroy()
            del self

        def tabFocused(self):
            resizeWindow(850,600)
            
        def UpdateSliderValue_scale(self):
            self.scale.set(self.scaleSlider.get())
            settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;scale&#34;, self.scaleSlider.get())
            UpdateSettings()
        def UpdateSliderValue_x1ofsc(self):
            self.x1ofsc.set(self.x1ofscSlider.get())
            settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;x1ofsc&#34;, self.x1ofscSlider.get())
            UpdateSettings()
        def UpdateSliderValue_y1ofsc(self):
            self.y1ofsc.set(self.y1ofscSlider.get())
            settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;y1ofsc&#34;, self.y1ofscSlider.get())
            UpdateSettings()
        def UpdateSliderValue_x2ofsc(self):
            self.x2ofsc.set(self.x2ofscSlider.get())
            settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;x2ofsc&#34;, self.x2ofscSlider.get())
            UpdateSettings()
        def UpdateSliderValue_y2ofsc(self):
            self.y2ofsc.set(self.y2ofscSlider.get())
            settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;y2ofsc&#34;, self.y2ofscSlider.get())
            UpdateSettings()
        def UpdateSliderValue_windowwidth(self):
            self.windowwidth.set(self.windowwidthSlider.get())
            settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;outputwindowwidth&#34;, self.windowwidthSlider.get())
            UpdateSettings()
        def UpdateSliderValue_windowheight(self):
            self.windowheight.set(self.windowheightSlider.get())
            settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;outputwindowheight&#34;, self.windowheightSlider.get())
            UpdateSettings()
        def UpdateSliderValue_minrectsize(self):
            self.minrectsize.set(self.minrectsizeSlider.get())
            settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;minrectsize&#34;, self.minrectsizeSlider.get())
            UpdateSettings()
        def UpdateSliderValue_maxrectsize(self):
            self.maxrectsize.set(self.maxrectsizeSlider.get())
            settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;maxrectsize&#34;, self.maxrectsizeSlider.get())
            UpdateSettings()
        
        def exampleFunction(self):
            
            try:
                self.root.destroy() 
            except: pass
            
            self.root = tk.Canvas(self.master, width=750, height=600, border=0, highlightthickness=0)
            self.root.grid_propagate(0) 
            self.root.pack_propagate(0)
            
            notebook = ttk.Notebook(self.root)
            notebook.pack(anchor=&#34;center&#34;, fill=&#34;both&#34;, expand=True)
            
            generalFrame = ttk.Frame(notebook)
            generalFrame.pack()
            screencaptureFrame = ttk.Frame(notebook)
            screencaptureFrame.pack()
            outputwindowFrame = ttk.Frame(notebook)
            outputwindowFrame.pack()
            trackeraiFrame = ttk.Frame(notebook)
            trackeraiFrame.pack()
            advancedFrame = ttk.Frame(notebook)
            advancedFrame.pack()

            advancedNotebook = ttk.Notebook(advancedFrame)
            advancedNotebook.grid_anchor(&#34;center&#34;)
            advancedNotebook.grid()
            
            colorsettingsFrame = ttk.Frame(advancedNotebook)
            colorsettingsFrame.pack()
            filtersFrame = ttk.Frame(advancedNotebook)
            filtersFrame.pack()


            colorsettingsFrame.columnconfigure(0, weight=1)
            colorsettingsFrame.columnconfigure(1, weight=1)
            colorsettingsFrame.columnconfigure(2, weight=1)
            helpers.MakeLabel(colorsettingsFrame, &#34;Color Settings&#34;, 0, 0, font=(&#34;Robot&#34;, 12, &#34;bold&#34;), columnspan=7)

            filtersFrame.columnconfigure(0, weight=1)
            filtersFrame.columnconfigure(1, weight=1)
            filtersFrame.columnconfigure(2, weight=1)
            helpers.MakeLabel(filtersFrame, &#34;Filters&#34;, 0, 0, font=(&#34;Robot&#34;, 12, &#34;bold&#34;), columnspan=3)

            generalFrame.columnconfigure(0, weight=1)
            generalFrame.columnconfigure(1, weight=1)
            generalFrame.columnconfigure(2, weight=1)
            helpers.MakeLabel(generalFrame, &#34;General&#34;, 0, 0, font=(&#34;Robot&#34;, 12, &#34;bold&#34;), columnspan=3)
            
            screencaptureFrame.columnconfigure(0, weight=1)
            screencaptureFrame.columnconfigure(1, weight=1)
            screencaptureFrame.columnconfigure(2, weight=1)
            helpers.MakeLabel(screencaptureFrame, &#34;Screen Capture&#34;, 0, 0, font=(&#34;Robot&#34;, 12, &#34;bold&#34;), columnspan=3)

            outputwindowFrame.columnconfigure(0, weight=1)
            outputwindowFrame.columnconfigure(1, weight=1)
            outputwindowFrame.columnconfigure(2, weight=1)
            helpers.MakeLabel(outputwindowFrame, &#34;Output Window&#34;, 0, 0, font=(&#34;Robot&#34;, 12, &#34;bold&#34;), columnspan=3)

            trackeraiFrame.columnconfigure(0, weight=1)
            trackeraiFrame.columnconfigure(1, weight=1)
            trackeraiFrame.columnconfigure(2, weight=1)
            helpers.MakeLabel(trackeraiFrame, &#34;Tracker/AI&#34;, 0, 0, font=(&#34;Robot&#34;, 12, &#34;bold&#34;), columnspan=7)

            advancedFrame.columnconfigure(0, weight=1)
            advancedFrame.columnconfigure(1, weight=1)
            advancedFrame.columnconfigure(2, weight=1)
            helpers.MakeLabel(advancedFrame, &#34;Advanced&#34;, 0, 0, font=(&#34;Robot&#34;, 12, &#34;bold&#34;), columnspan=7)
            

            notebook.add(generalFrame, text=Translate(&#34;General&#34;))
            notebook.add(screencaptureFrame, text=Translate(&#34;ScreenCapture&#34;))
            notebook.add(outputwindowFrame, text=Translate(&#34;OutputWindow&#34;))
            notebook.add(trackeraiFrame, text=Translate(&#34;Tracker/AI&#34;))
            notebook.add(advancedFrame, text=Translate(&#34;Advanced&#34;))
            advancedNotebook.add(colorsettingsFrame, text=Translate(&#34;ColorSettings&#34;))
            advancedNotebook.add(filtersFrame, text=Translate(&#34;Filters&#34;))
            
            self.root.pack(anchor=&#34;center&#34;, expand=False)
            self.root.update()


            helpers.MakeCheckButton(outputwindowFrame, &#34;Final Window\n--------------------\nIf enabled, the app creates a window with the result of the traffic light detection.&#34;, &#34;TrafficLightDetection&#34;, &#34;finalwindow&#34;, 1, 0, width=80, callback=lambda:UpdateSettings())
            helpers.MakeCheckButton(outputwindowFrame, &#34;Grayscale Window\n---------------------------\nIf enabled, the app creates a window with the color masks combined in a grayscaled frame.&#34;, &#34;TrafficLightDetection&#34;, &#34;grayscalewindow&#34;, 2, 0, width=80, callback=lambda:UpdateSettings())
            helpers.MakeCheckButton(outputwindowFrame, &#34;Red/Yellow/Green Window\n----------------------------\nIf enabled, the app creates a window with the color masks combined in a frame.&#34;, &#34;TrafficLightDetection&#34;, &#34;redyellowgreenwindow&#34;, 3, 0, width=80, callback=lambda:UpdateSettings())
            helpers.MakeCheckButton(outputwindowFrame, &#34;Automatic Windowsize\n---------------------------------\nIf enabled, the Window Width and Window Height sliders will no longer have any effect\nand the output window keeps the aspect ratio of the captured frame. Set the size of the\noutput window with the Window Scale slider.&#34;, &#34;TrafficLightDetection&#34;, &#34;automaticwindowsize&#34;, 4, 0, width=80, callback=lambda:UpdateSettings())
            helpers.MakeEmptyLine(outputwindowFrame,5,0)

            helpers.MakeCheckButton(generalFrame, &#34;Yellow Light Detection (not recommended)\n-------------------------------------------------------------\nIf enabled, the trafficlight detection tries to detect yellow traffic\nlights, but it is not recommended because it causes more wrong\ndetected traffic lights.&#34;, &#34;TrafficLightDetection&#34;, &#34;detectyellowlight&#34;, 4, 0, width=60, callback=lambda:UpdateSettings())
            helpers.MakeCheckButton(generalFrame, &#34;Performance Mode (recommended)\n---------------------------------------------------\nIf enabled, the traffic light detection only detects red traffic lights,\nwhich increases performance, but does not reduce detection accuracy.&#34;, &#34;TrafficLightDetection&#34;, &#34;performancemode&#34;, 5, 0, width=60, callback=lambda:UpdateSettings())
            helpers.MakeCheckButton(generalFrame, &#34;Advanced Settings\n---------------------------\nIf enabled, the traffic light detection uses the settings you set in\nthe Advanced tab. (could have a bad impact on performance)&#34;, &#34;TrafficLightDetection&#34;, &#34;advancedmode&#34;, 6, 0, width=60, callback=lambda:UpdateSettings())
            helpers.MakeEmptyLine(generalFrame,7,0)

            helpers.MakeCheckButton(filtersFrame, &#34;Rect Size Filter&#34;, &#34;TrafficLightDetection&#34;, &#34;rectsizefilter&#34;, 3, 0, width=60, callback=lambda:UpdateSettings())
            helpers.MakeCheckButton(filtersFrame, &#34;Width Height Ratio Filter&#34;, &#34;TrafficLightDetection&#34;, &#34;widthheightratiofilter&#34;, 4, 0, width=60, callback=lambda:UpdateSettings())
            helpers.MakeCheckButton(filtersFrame, &#34;Pixel Percentage Filter&#34;, &#34;TrafficLightDetection&#34;, &#34;pixelpercentagefilter&#34;, 5, 0, width=60, callback=lambda:UpdateSettings())
            helpers.MakeCheckButton(filtersFrame, &#34;Other Lights Filter&#34;, &#34;TrafficLightDetection&#34;, &#34;otherlightsofffilter&#34;, 6, 0, width=60, callback=lambda:UpdateSettings())

            helpers.MakeCheckButton(trackeraiFrame, &#34;Do Yolo Detection confirmation\n---------------------------------------------\nIf enabled, the app tracks the detected traffic lights and confirms them with the YOLO object detection.\nWhat this means: higher accuracy, but a small lag every time the detection detects a new traffic light.&#34;, &#34;TrafficLightDetection&#34;, &#34;yolo_detection&#34;, 1, 0, width=100, callback=lambda:UpdateSettings())
            helpers.MakeCheckButton(trackeraiFrame, &#34;Show unconfirmed traffic lights\n--------------------------------------------\nIf enabled, the app will show unconfirmed or wrongly detected traffic lights in gray in the output window.&#34;, &#34;TrafficLightDetection&#34;, &#34;yolo_showunconfirmed&#34;, 2, 0, width=100, callback=lambda:UpdateSettings())
            helpers.MakeEmptyLine(trackeraiFrame,3,0)
            helpers.MakeLabel(trackeraiFrame, &#34;YOLOv5 Model:&#34;, 4, 0, sticky=&#34;nw&#34;)
            model_ui = tk.StringVar() 
            previous_model_ui = settings.GetSettings(&#34;TrafficLightDetection&#34;, &#34;yolo_model&#34;)
            if previous_model_ui == &#34;yolov5n&#34;:
                model_ui.set(&#34;yolov5n&#34;)
            if previous_model_ui == &#34;yolov5s&#34;:
                model_ui.set(&#34;yolov5s&#34;)
            if previous_model_ui == &#34;yolov5m&#34;:
                model_ui.set(&#34;yolov5m&#34;)
            if previous_model_ui == &#34;yolov5l&#34;:
                model_ui.set(&#34;yolov5l&#34;)
            if previous_model_ui == &#34;yolov5x&#34;:
                model_ui.set(&#34;yolov5x&#34;)
            def model_selection():
                self.model_ui = model_ui.get()
            yolov5n = ttk.Radiobutton(trackeraiFrame, text=&#34;YOLOv5n (fastest, lowest accuracy) RECOMMENDED&#34;, variable=model_ui, value=&#34;yolov5n&#34;, command=model_selection)
            yolov5n.grid(row=5, column=0, sticky=&#34;nw&#34;)
            yolov5s = ttk.Radiobutton(trackeraiFrame, text=&#34;YOLOv5s (fast, low accuracy)&#34;, variable=model_ui, value=&#34;yolov5s&#34;, command=model_selection)
            yolov5s.grid(row=6, column=0, sticky=&#34;nw&#34;)
            yolov5m = ttk.Radiobutton(trackeraiFrame, text=&#34;YOLOv5m (slow, medium accuracy)&#34;, variable=model_ui, value=&#34;yolov5m&#34;, command=model_selection)
            yolov5m.grid(row=7, column=0, sticky=&#34;nw&#34;)
            yolov5l = ttk.Radiobutton(trackeraiFrame, text=&#34;YOLOv5l (slow, high accuracy)&#34;, variable=model_ui, value=&#34;yolov5l&#34;, command=model_selection)
            yolov5l.grid(row=8, column=0, sticky=&#34;nw&#34;)
            yolov5x = ttk.Radiobutton(trackeraiFrame, text=&#34;YOLOv5x (slowest, highest accuracy)&#34;, variable=model_ui, value=&#34;yolov5x&#34;, command=model_selection)
            yolov5x.grid(row=9, column=0, sticky=&#34;nw&#34;)
            model_selection()
            helpers.MakeButton(trackeraiFrame, &#34;Save and Load Model\n-------------------------------\nLoading the model could take some time.\nIt&#39;s normal that the app won&#39;t respond for a while.&#34;, self.save_and_load_model, 10, 0, width=50, sticky=&#34;nw&#34;)

            helpers.MakeCheckButton(screencaptureFrame, &#34;Use Full Frame\n----------------------\nIf enabled, the screencapture for the traffic light detection uses the top ⅔ of the screen for\nthe traffic light detection. (not recommended, could have a bad impact on performance)\n\nTo set own screencapture coordinates disable Use Full Frame and use sliders below.&#34;, &#34;TrafficLightDetection&#34;, &#34;usefullframe&#34;, 1, 0, width=80, callback=lambda:UpdateSettings())
            
            self.x1ofscSlider = tk.Scale(screencaptureFrame, from_=0, to=screen_width-1, resolution=1, orient=tk.HORIZONTAL, length=460, command=lambda x: self.UpdateSliderValue_x1ofsc())
            self.x1ofscSlider.set(settings.GetSettings(&#34;TrafficLightDetection&#34;, &#34;x1ofsc&#34;, 0))
            self.x1ofscSlider.grid(row=3, column=0, padx=10, pady=0, columnspan=2)
            self.x1ofsc = helpers.MakeComboEntry(screencaptureFrame, &#34;X1 (topleft)&#34;, &#34;TrafficLightDetection&#34;, &#34;x1ofsc&#34;, 3,0)

            self.y1ofscSlider = tk.Scale(screencaptureFrame, from_=0, to=screen_height-1, resolution=1, orient=tk.HORIZONTAL, length=460, command=lambda x: self.UpdateSliderValue_y1ofsc())
            self.y1ofscSlider.set(settings.GetSettings(&#34;TrafficLightDetection&#34;, &#34;y1ofsc&#34;, 0))
            self.y1ofscSlider.grid(row=5, column=0, padx=10, pady=0, columnspan=2)
            self.y1ofsc = helpers.MakeComboEntry(screencaptureFrame, &#34;Y1 (topleft)&#34;, &#34;TrafficLightDetection&#34;, &#34;y1ofsc&#34;, 5,0)

            self.x2ofscSlider = tk.Scale(screencaptureFrame, from_=0, to=screen_width-1, resolution=1, orient=tk.HORIZONTAL, length=460, command=lambda x: self.UpdateSliderValue_x2ofsc())
            self.x2ofscSlider.set(settings.GetSettings(&#34;TrafficLightDetection&#34;, &#34;x2ofsc&#34;, screen_width-1))
            self.x2ofscSlider.grid(row=7, column=0, padx=10, pady=0, columnspan=2)
            self.x2ofsc = helpers.MakeComboEntry(screencaptureFrame, &#34;X2 (buttomright)&#34;, &#34;TrafficLightDetection&#34;, &#34;x2ofsc&#34;, 7,0)

            self.y2ofscSlider = tk.Scale(screencaptureFrame, from_=0, to=screen_height-1, resolution=1, orient=tk.HORIZONTAL, length=460, command=lambda x: self.UpdateSliderValue_y2ofsc())
            self.y2ofscSlider.set(settings.GetSettings(&#34;TrafficLightDetection&#34;, &#34;y2ofsc&#34;, round(screen_height/1.5)-1))
            self.y2ofscSlider.grid(row=9, column=0, padx=10, pady=0, columnspan=2)
            self.y2ofsc = helpers.MakeComboEntry(screencaptureFrame, &#34;Y2 (buttomright)&#34;, &#34;TrafficLightDetection&#34;, &#34;y2ofsc&#34;, 9,0)

            helpers.MakeButton(screencaptureFrame, &#34;Open/Refresh preview&#34;, lambda: screencapture_open_refresh(), 11, 0, width=30, sticky=&#34;w&#34;)
            helpers.MakeButton(screencaptureFrame, &#34;Close preview&#34;, lambda: screencapture_close(), 12, 0, width=30, sticky=&#34;w&#34;)

            def screencapture_open_refresh():
                self.UpdateSliderValue_x1ofsc()
                self.UpdateSliderValue_y1ofsc()
                self.UpdateSliderValue_x2ofsc()
                self.UpdateSliderValue_y2ofsc()
                if settings.GetSettings(&#34;TrafficLightDetection&#34;, &#34;usefullframe&#34;, True) == False:
                    x1_preview = self.x1ofscSlider.get()
                    y1_preview = self.y1ofscSlider.get()
                    x2_preview = self.x2ofscSlider.get()
                    y2_preview = self.y2ofscSlider.get()
                    screenshot = cv2.cvtColor(np.array(pyautogui.screenshot(region=(x1_preview, y1_preview, x2_preview - x1_preview, y2_preview - y1_preview))), cv2.COLOR_RGB2BGR)
                else:
                    x1_preview = 0
                    y1_preview = 0
                    x2_preview = screen_width-1
                    y2_preview = round(screen_height/1.5)-1
                    screenshot = cv2.cvtColor(np.array(pyautogui.screenshot(region=(x1_preview, y1_preview, x2_preview - x1_preview, y2_preview - y1_preview))), cv2.COLOR_RGB2BGR)
                    current_text = &#39;&#34;Use Full Frame&#34; enabled, disable to set own screencapture area&#39;
                    width_target_current_text = (x2_preview - x1_preview)*0.9
                    fontscale_current_text = 1
                    textsize_current_text, _ = cv2.getTextSize(current_text, cv2.FONT_HERSHEY_SIMPLEX, fontscale_current_text, 1)
                    width_current_text, height_current_text = textsize_current_text
                    max_count_current_text = 3
                    while width_current_text != width_target_current_text:
                        fontscale_current_text *= width_target_current_text / width_current_text if width_current_text != 0 else 1
                        textsize_current_text, _ = cv2.getTextSize(current_text, cv2.FONT_HERSHEY_SIMPLEX, fontscale_current_text, 1)
                        width_current_text, height_current_text = textsize_current_text
                        max_count_current_text -= 1
                        if max_count_current_text &lt;= 0:
                            break
                    thickness_current_text = round(fontscale_current_text*2)
                    if thickness_current_text &lt;= 0:
                        thickness_current_text = 1
                    cv2.putText(screenshot, current_text, (round((x2-x1)/2 - width_current_text/2), height_current_text*2), cv2.FONT_HERSHEY_SIMPLEX, fontscale_current_text, (0, 0, 255), thickness_current_text)
                cv2.namedWindow(&#39;Screencapture Preview&#39;, cv2.WINDOW_NORMAL)
                cv2.setWindowProperty(&#39;Screencapture Preview&#39;, cv2.WND_PROP_TOPMOST, 1)
                cv2.resizeWindow(&#39;Screencapture Preview&#39;, round((x2-x1)/2), round((y2-y1)/2))
                cv2.imshow(&#39;Screencapture Preview&#39;, screenshot)
                cv2.waitKey(1)
                
            def screencapture_close():
                try: 
                    cv2.destroyWindow(&#39;Screencapture Preview&#39;)
                except: 
                    pass

            self.windowwidthSlider = tk.Scale(outputwindowFrame, from_=round(screen_width/20), to=screen_width, resolution=1, orient=tk.HORIZONTAL, length=480, command=lambda x: self.UpdateSliderValue_windowwidth())
            self.windowwidthSlider.set(settings.GetSettings(&#34;TrafficLightDetection&#34;, &#34;outputwindowwidth&#34;, round(screen_width/2)))
            self.windowwidthSlider.grid(row=6, column=0, padx=10, pady=0, columnspan=2)
            self.windowwidth = helpers.MakeComboEntry(outputwindowFrame, &#34;Window Width&#34;, &#34;TrafficLightDetection&#34;, &#34;outputwindowwidth&#34;, 6,0, labelwidth=13, width=10)

            self.windowheightSlider = tk.Scale(outputwindowFrame, from_=round(screen_height/20), to=screen_height, resolution=1, orient=tk.HORIZONTAL, length=480, command=lambda x: self.UpdateSliderValue_windowheight())
            self.windowheightSlider.set(settings.GetSettings(&#34;TrafficLightDetection&#34;, &#34;outputwindowheight&#34;, round(screen_height/3)))
            self.windowheightSlider.grid(row=7, column=0, padx=10, pady=0, columnspan=2)
            self.windowheight = helpers.MakeComboEntry(outputwindowFrame, &#34;Window Height&#34;, &#34;TrafficLightDetection&#34;, &#34;outputwindowheight&#34;, 7,0, labelwidth=13, width=10)

            self.scaleSlider = tk.Scale(outputwindowFrame, from_=0.1, to=2, resolution=0.01, orient=tk.HORIZONTAL, length=480, command=lambda x: self.UpdateSliderValue_scale())
            self.scaleSlider.set(settings.GetSettings(&#34;TrafficLightDetection&#34;, &#34;scale&#34;, 0.5))
            self.scaleSlider.grid(row=8, column=0, padx=10, pady=0, columnspan=2)
            self.scale = helpers.MakeComboEntry(outputwindowFrame, &#34;Window Scale&#34;, &#34;TrafficLightDetection&#34;, &#34;scale&#34;, 8,0, labelwidth=13, width=10)

            self.minrectsizeSlider = tk.Scale(filtersFrame, from_=1, to=round(screen_width / 2), resolution=1, orient=tk.HORIZONTAL, length=700, command=lambda x: self.UpdateSliderValue_minrectsize())
            self.minrectsizeSlider.set(settings.GetSettings(&#34;TrafficLightDetection&#34;, &#34;minrectsize&#34;, round(screen_width / 240)))
            self.minrectsizeSlider.grid(row=7, column=0, padx=10, pady=0, columnspan=2)
            self.minrectsize = helpers.MakeComboEntry(filtersFrame, &#34;Min. Traffic Light Size Filter&#34;, &#34;TrafficLightDetection&#34;, &#34;minrectsize&#34;, 8,0, labelwidth=80, width=20)

            self.maxrectsizeSlider = tk.Scale(filtersFrame, from_=1, to=round(screen_width / 2), resolution=1, orient=tk.HORIZONTAL, length=700, command=lambda x: self.UpdateSliderValue_maxrectsize())
            self.maxrectsizeSlider.set(settings.GetSettings(&#34;TrafficLightDetection&#34;, &#34;maxrectsize&#34;, round(screen_width / 10)))
            self.maxrectsizeSlider.grid(row=9, column=0, padx=10, pady=0, columnspan=2)
            self.maxrectsize = helpers.MakeComboEntry(filtersFrame, &#34;Max. Traffic Light Size Filter&#34;, &#34;TrafficLightDetection&#34;, &#34;maxrectsize&#34;, 10,0, labelwidth=80, width=20)

            self.upperredr = helpers.MakeComboEntry(colorsettingsFrame, &#34;RED:         Upper R:&#34;, &#34;TrafficLightDetection&#34;, &#34;upperred_r&#34;, 2, 0, labelwidth=20, width=7)
            self.upperredg = helpers.MakeComboEntry(colorsettingsFrame, &#34;Upper G:&#34;, &#34;TrafficLightDetection&#34;, &#34;upperred_g&#34;, 2, 2, labelwidth=13, width=7)
            self.upperredb = helpers.MakeComboEntry(colorsettingsFrame, &#34;Upper B:&#34;, &#34;TrafficLightDetection&#34;, &#34;upperred_b&#34;, 2, 4, labelwidth=13, width=7)
            self.lowerredr = helpers.MakeComboEntry(colorsettingsFrame, &#34;RED:         Lower R:&#34;, &#34;TrafficLightDetection&#34;, &#34;lowerred_r&#34;, 3, 0, labelwidth=20, width=7)
            self.lowerredg = helpers.MakeComboEntry(colorsettingsFrame, &#34;Lower G:&#34;, &#34;TrafficLightDetection&#34;, &#34;lowerred_g&#34;, 3, 2, labelwidth=13, width=7)
            self.lowerredb = helpers.MakeComboEntry(colorsettingsFrame, &#34;Lower B:&#34;, &#34;TrafficLightDetection&#34;, &#34;lowerred_b&#34;, 3, 4, labelwidth=13, width=7)
            self.upperyellowr = helpers.MakeComboEntry(colorsettingsFrame, &#34;YELLOW:  Upper R:&#34;, &#34;TrafficLightDetection&#34;, &#34;upperyellow_r&#34;, 4, 0, labelwidth=20, width=7)
            self.upperyellowg = helpers.MakeComboEntry(colorsettingsFrame, &#34;Upper G:&#34;, &#34;TrafficLightDetection&#34;, &#34;upperyellow_g&#34;, 4, 2, labelwidth=13, width=7)
            self.upperyellowb = helpers.MakeComboEntry(colorsettingsFrame, &#34;Upper B:&#34;, &#34;TrafficLightDetection&#34;, &#34;upperyellow_b&#34;, 4, 4, labelwidth=13, width=7)
            self.loweryellowr = helpers.MakeComboEntry(colorsettingsFrame, &#34;YELLOW:  Lower R:&#34;, &#34;TrafficLightDetection&#34;, &#34;loweryellow_r&#34;, 5, 0, labelwidth=20, width=7)
            self.loweryellowg = helpers.MakeComboEntry(colorsettingsFrame, &#34;Lower G:&#34;, &#34;TrafficLightDetection&#34;, &#34;loweryellow_g&#34;, 5, 2, labelwidth=13, width=7)
            self.loweryellowb = helpers.MakeComboEntry(colorsettingsFrame, &#34;Lower B:&#34;, &#34;TrafficLightDetection&#34;, &#34;loweryellow_b&#34;, 5, 4, labelwidth=13, width=7)
            self.uppergreenr = helpers.MakeComboEntry(colorsettingsFrame, &#34;GREEN:    Upper R:&#34;, &#34;TrafficLightDetection&#34;, &#34;uppergreen_r&#34;, 6, 0, labelwidth=20, width=7)
            self.uppergreeng = helpers.MakeComboEntry(colorsettingsFrame, &#34;Upper G:&#34;, &#34;TrafficLightDetection&#34;, &#34;uppergreen_g&#34;, 6, 2, labelwidth=13, width=7)
            self.uppergreenb = helpers.MakeComboEntry(colorsettingsFrame, &#34;Upper B:&#34;, &#34;TrafficLightDetection&#34;, &#34;uppergreen_b&#34;, 6, 4, labelwidth=13, width=7)
            self.lowergreenr = helpers.MakeComboEntry(colorsettingsFrame, &#34;GREEN:    Lower R:&#34;, &#34;TrafficLightDetection&#34;, &#34;lowergreen_r&#34;, 7, 0, labelwidth=20, width=7)
            self.lowergreeng = helpers.MakeComboEntry(colorsettingsFrame, &#34;Lower G:&#34;, &#34;TrafficLightDetection&#34;, &#34;lowergreen_g&#34;, 7, 2, labelwidth=13, width=7)
            self.lowergreenb = helpers.MakeComboEntry(colorsettingsFrame, &#34;Lower B:&#34;, &#34;TrafficLightDetection&#34;, &#34;lowergreen_b&#34;, 7, 4, labelwidth=13, width=7)
            helpers.MakeButton(colorsettingsFrame, &#34;Save&#34;, command=self.save, row=15, column=0, sticky=&#34;w&#34;)

            helpers.MakeLabel(colorsettingsFrame, &#34;&#34;, 13, 0, columnspan=7)
            helpers.MakeLabel(colorsettingsFrame, &#34;&#34;, 14, 0, columnspan=7)
            helpers.MakeButton(colorsettingsFrame, &#34;Reset&#34;, command=self.resetadvancedcolorstodefault, row=15, column=5)
            helpers.MakeEmptyLine(colorsettingsFrame,12,1)
            helpers.MakeEmptyLine(colorsettingsFrame,13,1)
            helpers.MakeEmptyLine(colorsettingsFrame,14,1)
            helpers.MakeButton(filtersFrame, &#34;Reset&#34;, command=self.resetadvancedfilterstodefault, row=15, column=1, width=20)
            helpers.MakeEmptyLine(filtersFrame,14,1)
            helpers.MakeButton(generalFrame, &#34;Reset Advanced Settings\nto Default\n------------------------------------&#34;, command=self.resetalladvancedsettingstodefault, row=6, column=1, width=32,)
            
        
        def save(self):
            
            try:
                self.upperredr.get()
            except:
                self.upperredr.set(255)
            try:
                self.upperredg.get()
            except:
                self.upperredg.set(110)
            try:
                self.upperredb.get()
            except:
                self.upperredb.set(110)
            try:
                self.lowerredr.get()
            except:
                self.lowerredr.set(200)
            try:
                self.lowerredg.get()
            except:
                self.lowerredg.set(0)
            try:
                self.lowerredb.get()
            except:
                self.lowerredb.set(0)
            try:
                self.upperyellowr.get()
            except:
                self.upperyellowr.set(255)
            try:
                self.upperyellowg.get()
            except:
                self.upperyellowg.set(240)
            try:
                self.upperyellowb.get()
            except:
                self.upperyellowb.set(170)
            try:
                self.loweryellowr.get()
            except:
                self.loweryellowr.set(200)
            try:
                self.loweryellowg.get()
            except:
                self.loweryellowg.set(170)
            try:
                self.loweryellowb.get()
            except:
                self.loweryellowb.set(50)
            try:
                self.uppergreenr.get()
            except:
                self.uppergreenr.set(150)
            try:
                self.uppergreeng.get()
            except:
                self.uppergreeng.set(255)
            try:
                self.uppergreenb.get()
            except:
                self.uppergreenb.set(230)
            try:
                self.lowergreenr.get()
            except:
                self.lowergreenr.set(0)
            try:
                self.lowergreeng.get()
            except:
                self.lowergreeng.set(200)
            try:
                self.lowergreenb.get()
            except:
                self.lowergreenb.set(0)
            if not (0 &lt;= self.upperredr.get() &lt;= 255):
                self.upperredr.set(255)
            if not (0 &lt;= self.upperredg.get() &lt;= 255):
                self.upperredg.set(110)
            if not (0 &lt;= self.upperredb.get() &lt;= 255):
                self.upperredb.set(110)
            if not (0 &lt;= self.lowerredr.get() &lt;= 255):
                self.lowerredr.set(200)  
            if not (0 &lt;= self.lowerredg.get() &lt;= 255):
                self.lowerredg.set(0)
            if not (0 &lt;= self.lowerredb.get() &lt;= 255):
                self.lowerredb.set(0)
            if not (0 &lt;= self.upperyellowr.get() &lt;= 255):
                self.upperyellowr.set(255)
            if not (0 &lt;= self.upperyellowg.get() &lt;= 255):
                self.upperyellowg.set(240)
            if not (0 &lt;= self.upperyellowb.get() &lt;= 255):
                self.upperyellowb.set(170)
            if not (0 &lt;= self.loweryellowr.get() &lt;= 255):
                self.loweryellowr.set(200)
            if not (0 &lt;= self.loweryellowg.get() &lt;= 255):
                self.loweryellowg.set(170)
            if not (0 &lt;= self.loweryellowb.get() &lt;= 255):
                self.loweryellowb.set(50)
            if not (0 &lt;= self.uppergreenr.get() &lt;= 255):
                self.uppergreenr.set(150)
            if not (0 &lt;= self.uppergreeng.get() &lt;= 255):
                self.uppergreeng.set(255)
            if not (0 &lt;= self.uppergreenb.get() &lt;= 255):
                self.uppergreenb.set(230)
            if not (0 &lt;= self.lowergreenr.get() &lt;= 255):
                self.lowergreenr.set(0)
            if not (0 &lt;= self.lowergreeng.get() &lt;= 255):
                self.lowergreeng.set(200)
            if not (0 &lt;= self.lowergreenb.get() &lt;= 255):
                self.lowergreenb.set(0)
            settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;upperred_r&#34;, self.upperredr.get())
            settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;upperred_g&#34;, self.upperredg.get())
            settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;upperred_b&#34;, self.upperredb.get())
            settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;lowerred_r&#34;, self.lowerredr.get())
            settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;lowerred_g&#34;, self.lowerredg.get())
            settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;lowerred_b&#34;, self.lowerredb.get())
            settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;upperyellow_r&#34;, self.upperyellowr.get())
            settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;upperyellow_g&#34;, self.upperyellowg.get())
            settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;upperyellow_b&#34;, self.upperyellowb.get())
            settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;loweryellow_r&#34;, self.loweryellowr.get())
            settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;loweryellow_g&#34;, self.loweryellowg.get())
            settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;loweryellow_b&#34;, self.loweryellowb.get())
            settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;uppergreen_r&#34;, self.uppergreenr.get())
            settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;uppergreen_g&#34;, self.uppergreeng.get())
            settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;uppergreen_b&#34;, self.uppergreenb.get())
            settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;lowergreen_r&#34;, self.lowergreenr.get())
            settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;lowergreen_g&#34;, self.lowergreeng.get())
            settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;lowergreen_b&#34;, self.lowergreenb.get())
            UpdateSettings()

        
        def resetadvancedcolorstodefault(self):
            settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;upperred_r&#34;, 255)
            settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;upperred_g&#34;, 110)
            settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;upperred_b&#34;, 110)
            settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;lowerred_r&#34;, 200)
            settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;lowerred_g&#34;, 0)
            settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;lowerred_b&#34;, 0)
            settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;upperyellow_r&#34;, 255)
            settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;upperyellow_g&#34;, 240)
            settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;upperyellow_b&#34;, 170)
            settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;loweryellow_r&#34;, 200)
            settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;loweryellow_g&#34;, 170)
            settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;loweryellow_b&#34;, 50)
            settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;uppergreen_r&#34;, 150)
            settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;uppergreen_g&#34;, 255)
            settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;uppergreen_b&#34;, 230)
            settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;lowergreen_r&#34;, 0)
            settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;lowergreen_g&#34;, 200)
            settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;lowergreen_b&#34;, 0)
            self.upperredr.set(255)
            self.upperredg.set(110)
            self.upperredb.set(110)
            self.lowerredr.set(200)
            self.lowerredg.set(0)
            self.lowerredb.set(0)
            self.upperyellowr.set(255)
            self.upperyellowg.set(240)
            self.upperyellowb.set(170)
            self.loweryellowr.set(200)
            self.loweryellowg.set(170)
            self.loweryellowb.set(50)
            self.uppergreenr.set(150)
            self.uppergreeng.set(255)
            self.uppergreenb.set(230)
            self.lowergreenr.set(0)
            self.lowergreeng.set(200)
            self.lowergreenb.set(0)
            UpdateSettings()

        def resetadvancedfilterstodefault(self):
            settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;rectsizefilter&#34;, True)
            settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;widthheightratiofilter&#34;, True)
            settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;pixelpercentagefilter&#34;, True)
            settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;otherlightsofffilter&#34;, True)

            settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;minrectsize&#34;, round(screen_width / 240))
            settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;maxrectsize&#34;, round(screen_width / 10))
            self.minrectsizeSlider.set(round(screen_width / 240))
            self.minrectsize.set(round(screen_width / 240))
            self.maxrectsizeSlider.set(round(screen_width / 10))
            self.maxrectsize.set(round(screen_width / 10))
            self.exampleFunction()
            UpdateSettings()

        def resetalladvancedsettingstodefault(self):
            settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;rectsizefilter&#34;, True)
            settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;widthheightratiofilter&#34;, True)
            settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;pixelpercentagefilter&#34;, True)
            settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;otherlightsofffilter&#34;, True)

            settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;minrectsize&#34;, round(screen_width / 240))
            settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;maxrectsize&#34;, round(screen_width / 10))

            settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;upperred_r&#34;, 255)
            settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;upperred_g&#34;, 110)
            settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;upperred_b&#34;, 110)
            settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;lowerred_r&#34;, 200)
            settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;lowerred_g&#34;, 0)
            settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;lowerred_b&#34;, 0)
            settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;upperyellow_r&#34;, 255)
            settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;upperyellow_g&#34;, 240)
            settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;upperyellow_b&#34;, 170)
            settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;loweryellow_r&#34;, 200)
            settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;loweryellow_g&#34;, 170)
            settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;loweryellow_b&#34;, 50)
            settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;uppergreen_r&#34;, 150)
            settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;uppergreen_g&#34;, 255)
            settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;uppergreen_b&#34;, 230)
            settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;lowergreen_r&#34;, 0)
            settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;lowergreen_g&#34;, 200)
            settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;lowergreen_b&#34;, 0)
            self.upperredr.set(255)
            self.upperredg.set(110)
            self.upperredb.set(110)
            self.lowerredr.set(200)
            self.lowerredg.set(0)
            self.lowerredb.set(0)
            self.upperyellowr.set(255)
            self.upperyellowg.set(240)
            self.upperyellowb.set(170)
            self.loweryellowr.set(200)
            self.loweryellowg.set(170)
            self.loweryellowb.set(50)
            self.uppergreenr.set(150)
            self.uppergreeng.set(255)
            self.uppergreenb.set(230)
            self.lowergreenr.set(0)
            self.lowergreeng.set(200)
            self.lowergreenb.set(0)
            self.exampleFunction()
            UpdateSettings()

        def save_and_load_model(self):
            global yolo_model_loaded
            yolo_model_loaded = False
            settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;yolo_model&#34;, self.model_ui)
            loadYOLO()
            UpdateSettings()
        
        def update(self, data): 
            self.root.update()
            
    except Exception as ex:
        print(ex.args)</code></pre>
</details>
<h3>Methods</h3>
<dl>
<dt id="Euro-Truck-Simulator-2-Lane-Assist.plugins.TrafficLightDetection.main.UI.UpdateSliderValue_maxrectsize"><code class="name flex">
<span>def <span class="ident">UpdateSliderValue_maxrectsize</span></span>(<span>self)</span>
</code></dt>
<dd>
<div class="desc"></div>
<details class="source">
<summary>
<span>Expand source code</span>
</summary>
<pre><code class="python">def UpdateSliderValue_maxrectsize(self):
    self.maxrectsize.set(self.maxrectsizeSlider.get())
    settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;maxrectsize&#34;, self.maxrectsizeSlider.get())
    UpdateSettings()</code></pre>
</details>
</dd>
<dt id="Euro-Truck-Simulator-2-Lane-Assist.plugins.TrafficLightDetection.main.UI.UpdateSliderValue_minrectsize"><code class="name flex">
<span>def <span class="ident">UpdateSliderValue_minrectsize</span></span>(<span>self)</span>
</code></dt>
<dd>
<div class="desc"></div>
<details class="source">
<summary>
<span>Expand source code</span>
</summary>
<pre><code class="python">def UpdateSliderValue_minrectsize(self):
    self.minrectsize.set(self.minrectsizeSlider.get())
    settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;minrectsize&#34;, self.minrectsizeSlider.get())
    UpdateSettings()</code></pre>
</details>
</dd>
<dt id="Euro-Truck-Simulator-2-Lane-Assist.plugins.TrafficLightDetection.main.UI.UpdateSliderValue_scale"><code class="name flex">
<span>def <span class="ident">UpdateSliderValue_scale</span></span>(<span>self)</span>
</code></dt>
<dd>
<div class="desc"></div>
<details class="source">
<summary>
<span>Expand source code</span>
</summary>
<pre><code class="python">def UpdateSliderValue_scale(self):
    self.scale.set(self.scaleSlider.get())
    settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;scale&#34;, self.scaleSlider.get())
    UpdateSettings()</code></pre>
</details>
</dd>
<dt id="Euro-Truck-Simulator-2-Lane-Assist.plugins.TrafficLightDetection.main.UI.UpdateSliderValue_windowheight"><code class="name flex">
<span>def <span class="ident">UpdateSliderValue_windowheight</span></span>(<span>self)</span>
</code></dt>
<dd>
<div class="desc"></div>
<details class="source">
<summary>
<span>Expand source code</span>
</summary>
<pre><code class="python">def UpdateSliderValue_windowheight(self):
    self.windowheight.set(self.windowheightSlider.get())
    settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;outputwindowheight&#34;, self.windowheightSlider.get())
    UpdateSettings()</code></pre>
</details>
</dd>
<dt id="Euro-Truck-Simulator-2-Lane-Assist.plugins.TrafficLightDetection.main.UI.UpdateSliderValue_windowwidth"><code class="name flex">
<span>def <span class="ident">UpdateSliderValue_windowwidth</span></span>(<span>self)</span>
</code></dt>
<dd>
<div class="desc"></div>
<details class="source">
<summary>
<span>Expand source code</span>
</summary>
<pre><code class="python">def UpdateSliderValue_windowwidth(self):
    self.windowwidth.set(self.windowwidthSlider.get())
    settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;outputwindowwidth&#34;, self.windowwidthSlider.get())
    UpdateSettings()</code></pre>
</details>
</dd>
<dt id="Euro-Truck-Simulator-2-Lane-Assist.plugins.TrafficLightDetection.main.UI.UpdateSliderValue_x1ofsc"><code class="name flex">
<span>def <span class="ident">UpdateSliderValue_x1ofsc</span></span>(<span>self)</span>
</code></dt>
<dd>
<div class="desc"></div>
<details class="source">
<summary>
<span>Expand source code</span>
</summary>
<pre><code class="python">def UpdateSliderValue_x1ofsc(self):
    self.x1ofsc.set(self.x1ofscSlider.get())
    settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;x1ofsc&#34;, self.x1ofscSlider.get())
    UpdateSettings()</code></pre>
</details>
</dd>
<dt id="Euro-Truck-Simulator-2-Lane-Assist.plugins.TrafficLightDetection.main.UI.UpdateSliderValue_x2ofsc"><code class="name flex">
<span>def <span class="ident">UpdateSliderValue_x2ofsc</span></span>(<span>self)</span>
</code></dt>
<dd>
<div class="desc"></div>
<details class="source">
<summary>
<span>Expand source code</span>
</summary>
<pre><code class="python">def UpdateSliderValue_x2ofsc(self):
    self.x2ofsc.set(self.x2ofscSlider.get())
    settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;x2ofsc&#34;, self.x2ofscSlider.get())
    UpdateSettings()</code></pre>
</details>
</dd>
<dt id="Euro-Truck-Simulator-2-Lane-Assist.plugins.TrafficLightDetection.main.UI.UpdateSliderValue_y1ofsc"><code class="name flex">
<span>def <span class="ident">UpdateSliderValue_y1ofsc</span></span>(<span>self)</span>
</code></dt>
<dd>
<div class="desc"></div>
<details class="source">
<summary>
<span>Expand source code</span>
</summary>
<pre><code class="python">def UpdateSliderValue_y1ofsc(self):
    self.y1ofsc.set(self.y1ofscSlider.get())
    settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;y1ofsc&#34;, self.y1ofscSlider.get())
    UpdateSettings()</code></pre>
</details>
</dd>
<dt id="Euro-Truck-Simulator-2-Lane-Assist.plugins.TrafficLightDetection.main.UI.UpdateSliderValue_y2ofsc"><code class="name flex">
<span>def <span class="ident">UpdateSliderValue_y2ofsc</span></span>(<span>self)</span>
</code></dt>
<dd>
<div class="desc"></div>
<details class="source">
<summary>
<span>Expand source code</span>
</summary>
<pre><code class="python">def UpdateSliderValue_y2ofsc(self):
    self.y2ofsc.set(self.y2ofscSlider.get())
    settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;y2ofsc&#34;, self.y2ofscSlider.get())
    UpdateSettings()</code></pre>
</details>
</dd>
<dt id="Euro-Truck-Simulator-2-Lane-Assist.plugins.TrafficLightDetection.main.UI.destroy"><code class="name flex">
<span>def <span class="ident">destroy</span></span>(<span>self)</span>
</code></dt>
<dd>
<div class="desc"></div>
<details class="source">
<summary>
<span>Expand source code</span>
</summary>
<pre><code class="python">def destroy(self):
    self.done = True
    self.root.destroy()
    del self</code></pre>
</details>
</dd>
<dt id="Euro-Truck-Simulator-2-Lane-Assist.plugins.TrafficLightDetection.main.UI.exampleFunction"><code class="name flex">
<span>def <span class="ident">exampleFunction</span></span>(<span>self)</span>
</code></dt>
<dd>
<div class="desc"></div>
<details class="source">
<summary>
<span>Expand source code</span>
</summary>
<pre><code class="python">def exampleFunction(self):
    
    try:
        self.root.destroy() 
    except: pass
    
    self.root = tk.Canvas(self.master, width=750, height=600, border=0, highlightthickness=0)
    self.root.grid_propagate(0) 
    self.root.pack_propagate(0)
    
    notebook = ttk.Notebook(self.root)
    notebook.pack(anchor=&#34;center&#34;, fill=&#34;both&#34;, expand=True)
    
    generalFrame = ttk.Frame(notebook)
    generalFrame.pack()
    screencaptureFrame = ttk.Frame(notebook)
    screencaptureFrame.pack()
    outputwindowFrame = ttk.Frame(notebook)
    outputwindowFrame.pack()
    trackeraiFrame = ttk.Frame(notebook)
    trackeraiFrame.pack()
    advancedFrame = ttk.Frame(notebook)
    advancedFrame.pack()

    advancedNotebook = ttk.Notebook(advancedFrame)
    advancedNotebook.grid_anchor(&#34;center&#34;)
    advancedNotebook.grid()
    
    colorsettingsFrame = ttk.Frame(advancedNotebook)
    colorsettingsFrame.pack()
    filtersFrame = ttk.Frame(advancedNotebook)
    filtersFrame.pack()


    colorsettingsFrame.columnconfigure(0, weight=1)
    colorsettingsFrame.columnconfigure(1, weight=1)
    colorsettingsFrame.columnconfigure(2, weight=1)
    helpers.MakeLabel(colorsettingsFrame, &#34;Color Settings&#34;, 0, 0, font=(&#34;Robot&#34;, 12, &#34;bold&#34;), columnspan=7)

    filtersFrame.columnconfigure(0, weight=1)
    filtersFrame.columnconfigure(1, weight=1)
    filtersFrame.columnconfigure(2, weight=1)
    helpers.MakeLabel(filtersFrame, &#34;Filters&#34;, 0, 0, font=(&#34;Robot&#34;, 12, &#34;bold&#34;), columnspan=3)

    generalFrame.columnconfigure(0, weight=1)
    generalFrame.columnconfigure(1, weight=1)
    generalFrame.columnconfigure(2, weight=1)
    helpers.MakeLabel(generalFrame, &#34;General&#34;, 0, 0, font=(&#34;Robot&#34;, 12, &#34;bold&#34;), columnspan=3)
    
    screencaptureFrame.columnconfigure(0, weight=1)
    screencaptureFrame.columnconfigure(1, weight=1)
    screencaptureFrame.columnconfigure(2, weight=1)
    helpers.MakeLabel(screencaptureFrame, &#34;Screen Capture&#34;, 0, 0, font=(&#34;Robot&#34;, 12, &#34;bold&#34;), columnspan=3)

    outputwindowFrame.columnconfigure(0, weight=1)
    outputwindowFrame.columnconfigure(1, weight=1)
    outputwindowFrame.columnconfigure(2, weight=1)
    helpers.MakeLabel(outputwindowFrame, &#34;Output Window&#34;, 0, 0, font=(&#34;Robot&#34;, 12, &#34;bold&#34;), columnspan=3)

    trackeraiFrame.columnconfigure(0, weight=1)
    trackeraiFrame.columnconfigure(1, weight=1)
    trackeraiFrame.columnconfigure(2, weight=1)
    helpers.MakeLabel(trackeraiFrame, &#34;Tracker/AI&#34;, 0, 0, font=(&#34;Robot&#34;, 12, &#34;bold&#34;), columnspan=7)

    advancedFrame.columnconfigure(0, weight=1)
    advancedFrame.columnconfigure(1, weight=1)
    advancedFrame.columnconfigure(2, weight=1)
    helpers.MakeLabel(advancedFrame, &#34;Advanced&#34;, 0, 0, font=(&#34;Robot&#34;, 12, &#34;bold&#34;), columnspan=7)
    

    notebook.add(generalFrame, text=Translate(&#34;General&#34;))
    notebook.add(screencaptureFrame, text=Translate(&#34;ScreenCapture&#34;))
    notebook.add(outputwindowFrame, text=Translate(&#34;OutputWindow&#34;))
    notebook.add(trackeraiFrame, text=Translate(&#34;Tracker/AI&#34;))
    notebook.add(advancedFrame, text=Translate(&#34;Advanced&#34;))
    advancedNotebook.add(colorsettingsFrame, text=Translate(&#34;ColorSettings&#34;))
    advancedNotebook.add(filtersFrame, text=Translate(&#34;Filters&#34;))
    
    self.root.pack(anchor=&#34;center&#34;, expand=False)
    self.root.update()


    helpers.MakeCheckButton(outputwindowFrame, &#34;Final Window\n--------------------\nIf enabled, the app creates a window with the result of the traffic light detection.&#34;, &#34;TrafficLightDetection&#34;, &#34;finalwindow&#34;, 1, 0, width=80, callback=lambda:UpdateSettings())
    helpers.MakeCheckButton(outputwindowFrame, &#34;Grayscale Window\n---------------------------\nIf enabled, the app creates a window with the color masks combined in a grayscaled frame.&#34;, &#34;TrafficLightDetection&#34;, &#34;grayscalewindow&#34;, 2, 0, width=80, callback=lambda:UpdateSettings())
    helpers.MakeCheckButton(outputwindowFrame, &#34;Red/Yellow/Green Window\n----------------------------\nIf enabled, the app creates a window with the color masks combined in a frame.&#34;, &#34;TrafficLightDetection&#34;, &#34;redyellowgreenwindow&#34;, 3, 0, width=80, callback=lambda:UpdateSettings())
    helpers.MakeCheckButton(outputwindowFrame, &#34;Automatic Windowsize\n---------------------------------\nIf enabled, the Window Width and Window Height sliders will no longer have any effect\nand the output window keeps the aspect ratio of the captured frame. Set the size of the\noutput window with the Window Scale slider.&#34;, &#34;TrafficLightDetection&#34;, &#34;automaticwindowsize&#34;, 4, 0, width=80, callback=lambda:UpdateSettings())
    helpers.MakeEmptyLine(outputwindowFrame,5,0)

    helpers.MakeCheckButton(generalFrame, &#34;Yellow Light Detection (not recommended)\n-------------------------------------------------------------\nIf enabled, the trafficlight detection tries to detect yellow traffic\nlights, but it is not recommended because it causes more wrong\ndetected traffic lights.&#34;, &#34;TrafficLightDetection&#34;, &#34;detectyellowlight&#34;, 4, 0, width=60, callback=lambda:UpdateSettings())
    helpers.MakeCheckButton(generalFrame, &#34;Performance Mode (recommended)\n---------------------------------------------------\nIf enabled, the traffic light detection only detects red traffic lights,\nwhich increases performance, but does not reduce detection accuracy.&#34;, &#34;TrafficLightDetection&#34;, &#34;performancemode&#34;, 5, 0, width=60, callback=lambda:UpdateSettings())
    helpers.MakeCheckButton(generalFrame, &#34;Advanced Settings\n---------------------------\nIf enabled, the traffic light detection uses the settings you set in\nthe Advanced tab. (could have a bad impact on performance)&#34;, &#34;TrafficLightDetection&#34;, &#34;advancedmode&#34;, 6, 0, width=60, callback=lambda:UpdateSettings())
    helpers.MakeEmptyLine(generalFrame,7,0)

    helpers.MakeCheckButton(filtersFrame, &#34;Rect Size Filter&#34;, &#34;TrafficLightDetection&#34;, &#34;rectsizefilter&#34;, 3, 0, width=60, callback=lambda:UpdateSettings())
    helpers.MakeCheckButton(filtersFrame, &#34;Width Height Ratio Filter&#34;, &#34;TrafficLightDetection&#34;, &#34;widthheightratiofilter&#34;, 4, 0, width=60, callback=lambda:UpdateSettings())
    helpers.MakeCheckButton(filtersFrame, &#34;Pixel Percentage Filter&#34;, &#34;TrafficLightDetection&#34;, &#34;pixelpercentagefilter&#34;, 5, 0, width=60, callback=lambda:UpdateSettings())
    helpers.MakeCheckButton(filtersFrame, &#34;Other Lights Filter&#34;, &#34;TrafficLightDetection&#34;, &#34;otherlightsofffilter&#34;, 6, 0, width=60, callback=lambda:UpdateSettings())

    helpers.MakeCheckButton(trackeraiFrame, &#34;Do Yolo Detection confirmation\n---------------------------------------------\nIf enabled, the app tracks the detected traffic lights and confirms them with the YOLO object detection.\nWhat this means: higher accuracy, but a small lag every time the detection detects a new traffic light.&#34;, &#34;TrafficLightDetection&#34;, &#34;yolo_detection&#34;, 1, 0, width=100, callback=lambda:UpdateSettings())
    helpers.MakeCheckButton(trackeraiFrame, &#34;Show unconfirmed traffic lights\n--------------------------------------------\nIf enabled, the app will show unconfirmed or wrongly detected traffic lights in gray in the output window.&#34;, &#34;TrafficLightDetection&#34;, &#34;yolo_showunconfirmed&#34;, 2, 0, width=100, callback=lambda:UpdateSettings())
    helpers.MakeEmptyLine(trackeraiFrame,3,0)
    helpers.MakeLabel(trackeraiFrame, &#34;YOLOv5 Model:&#34;, 4, 0, sticky=&#34;nw&#34;)
    model_ui = tk.StringVar() 
    previous_model_ui = settings.GetSettings(&#34;TrafficLightDetection&#34;, &#34;yolo_model&#34;)
    if previous_model_ui == &#34;yolov5n&#34;:
        model_ui.set(&#34;yolov5n&#34;)
    if previous_model_ui == &#34;yolov5s&#34;:
        model_ui.set(&#34;yolov5s&#34;)
    if previous_model_ui == &#34;yolov5m&#34;:
        model_ui.set(&#34;yolov5m&#34;)
    if previous_model_ui == &#34;yolov5l&#34;:
        model_ui.set(&#34;yolov5l&#34;)
    if previous_model_ui == &#34;yolov5x&#34;:
        model_ui.set(&#34;yolov5x&#34;)
    def model_selection():
        self.model_ui = model_ui.get()
    yolov5n = ttk.Radiobutton(trackeraiFrame, text=&#34;YOLOv5n (fastest, lowest accuracy) RECOMMENDED&#34;, variable=model_ui, value=&#34;yolov5n&#34;, command=model_selection)
    yolov5n.grid(row=5, column=0, sticky=&#34;nw&#34;)
    yolov5s = ttk.Radiobutton(trackeraiFrame, text=&#34;YOLOv5s (fast, low accuracy)&#34;, variable=model_ui, value=&#34;yolov5s&#34;, command=model_selection)
    yolov5s.grid(row=6, column=0, sticky=&#34;nw&#34;)
    yolov5m = ttk.Radiobutton(trackeraiFrame, text=&#34;YOLOv5m (slow, medium accuracy)&#34;, variable=model_ui, value=&#34;yolov5m&#34;, command=model_selection)
    yolov5m.grid(row=7, column=0, sticky=&#34;nw&#34;)
    yolov5l = ttk.Radiobutton(trackeraiFrame, text=&#34;YOLOv5l (slow, high accuracy)&#34;, variable=model_ui, value=&#34;yolov5l&#34;, command=model_selection)
    yolov5l.grid(row=8, column=0, sticky=&#34;nw&#34;)
    yolov5x = ttk.Radiobutton(trackeraiFrame, text=&#34;YOLOv5x (slowest, highest accuracy)&#34;, variable=model_ui, value=&#34;yolov5x&#34;, command=model_selection)
    yolov5x.grid(row=9, column=0, sticky=&#34;nw&#34;)
    model_selection()
    helpers.MakeButton(trackeraiFrame, &#34;Save and Load Model\n-------------------------------\nLoading the model could take some time.\nIt&#39;s normal that the app won&#39;t respond for a while.&#34;, self.save_and_load_model, 10, 0, width=50, sticky=&#34;nw&#34;)

    helpers.MakeCheckButton(screencaptureFrame, &#34;Use Full Frame\n----------------------\nIf enabled, the screencapture for the traffic light detection uses the top ⅔ of the screen for\nthe traffic light detection. (not recommended, could have a bad impact on performance)\n\nTo set own screencapture coordinates disable Use Full Frame and use sliders below.&#34;, &#34;TrafficLightDetection&#34;, &#34;usefullframe&#34;, 1, 0, width=80, callback=lambda:UpdateSettings())
    
    self.x1ofscSlider = tk.Scale(screencaptureFrame, from_=0, to=screen_width-1, resolution=1, orient=tk.HORIZONTAL, length=460, command=lambda x: self.UpdateSliderValue_x1ofsc())
    self.x1ofscSlider.set(settings.GetSettings(&#34;TrafficLightDetection&#34;, &#34;x1ofsc&#34;, 0))
    self.x1ofscSlider.grid(row=3, column=0, padx=10, pady=0, columnspan=2)
    self.x1ofsc = helpers.MakeComboEntry(screencaptureFrame, &#34;X1 (topleft)&#34;, &#34;TrafficLightDetection&#34;, &#34;x1ofsc&#34;, 3,0)

    self.y1ofscSlider = tk.Scale(screencaptureFrame, from_=0, to=screen_height-1, resolution=1, orient=tk.HORIZONTAL, length=460, command=lambda x: self.UpdateSliderValue_y1ofsc())
    self.y1ofscSlider.set(settings.GetSettings(&#34;TrafficLightDetection&#34;, &#34;y1ofsc&#34;, 0))
    self.y1ofscSlider.grid(row=5, column=0, padx=10, pady=0, columnspan=2)
    self.y1ofsc = helpers.MakeComboEntry(screencaptureFrame, &#34;Y1 (topleft)&#34;, &#34;TrafficLightDetection&#34;, &#34;y1ofsc&#34;, 5,0)

    self.x2ofscSlider = tk.Scale(screencaptureFrame, from_=0, to=screen_width-1, resolution=1, orient=tk.HORIZONTAL, length=460, command=lambda x: self.UpdateSliderValue_x2ofsc())
    self.x2ofscSlider.set(settings.GetSettings(&#34;TrafficLightDetection&#34;, &#34;x2ofsc&#34;, screen_width-1))
    self.x2ofscSlider.grid(row=7, column=0, padx=10, pady=0, columnspan=2)
    self.x2ofsc = helpers.MakeComboEntry(screencaptureFrame, &#34;X2 (buttomright)&#34;, &#34;TrafficLightDetection&#34;, &#34;x2ofsc&#34;, 7,0)

    self.y2ofscSlider = tk.Scale(screencaptureFrame, from_=0, to=screen_height-1, resolution=1, orient=tk.HORIZONTAL, length=460, command=lambda x: self.UpdateSliderValue_y2ofsc())
    self.y2ofscSlider.set(settings.GetSettings(&#34;TrafficLightDetection&#34;, &#34;y2ofsc&#34;, round(screen_height/1.5)-1))
    self.y2ofscSlider.grid(row=9, column=0, padx=10, pady=0, columnspan=2)
    self.y2ofsc = helpers.MakeComboEntry(screencaptureFrame, &#34;Y2 (buttomright)&#34;, &#34;TrafficLightDetection&#34;, &#34;y2ofsc&#34;, 9,0)

    helpers.MakeButton(screencaptureFrame, &#34;Open/Refresh preview&#34;, lambda: screencapture_open_refresh(), 11, 0, width=30, sticky=&#34;w&#34;)
    helpers.MakeButton(screencaptureFrame, &#34;Close preview&#34;, lambda: screencapture_close(), 12, 0, width=30, sticky=&#34;w&#34;)

    def screencapture_open_refresh():
        self.UpdateSliderValue_x1ofsc()
        self.UpdateSliderValue_y1ofsc()
        self.UpdateSliderValue_x2ofsc()
        self.UpdateSliderValue_y2ofsc()
        if settings.GetSettings(&#34;TrafficLightDetection&#34;, &#34;usefullframe&#34;, True) == False:
            x1_preview = self.x1ofscSlider.get()
            y1_preview = self.y1ofscSlider.get()
            x2_preview = self.x2ofscSlider.get()
            y2_preview = self.y2ofscSlider.get()
            screenshot = cv2.cvtColor(np.array(pyautogui.screenshot(region=(x1_preview, y1_preview, x2_preview - x1_preview, y2_preview - y1_preview))), cv2.COLOR_RGB2BGR)
        else:
            x1_preview = 0
            y1_preview = 0
            x2_preview = screen_width-1
            y2_preview = round(screen_height/1.5)-1
            screenshot = cv2.cvtColor(np.array(pyautogui.screenshot(region=(x1_preview, y1_preview, x2_preview - x1_preview, y2_preview - y1_preview))), cv2.COLOR_RGB2BGR)
            current_text = &#39;&#34;Use Full Frame&#34; enabled, disable to set own screencapture area&#39;
            width_target_current_text = (x2_preview - x1_preview)*0.9
            fontscale_current_text = 1
            textsize_current_text, _ = cv2.getTextSize(current_text, cv2.FONT_HERSHEY_SIMPLEX, fontscale_current_text, 1)
            width_current_text, height_current_text = textsize_current_text
            max_count_current_text = 3
            while width_current_text != width_target_current_text:
                fontscale_current_text *= width_target_current_text / width_current_text if width_current_text != 0 else 1
                textsize_current_text, _ = cv2.getTextSize(current_text, cv2.FONT_HERSHEY_SIMPLEX, fontscale_current_text, 1)
                width_current_text, height_current_text = textsize_current_text
                max_count_current_text -= 1
                if max_count_current_text &lt;= 0:
                    break
            thickness_current_text = round(fontscale_current_text*2)
            if thickness_current_text &lt;= 0:
                thickness_current_text = 1
            cv2.putText(screenshot, current_text, (round((x2-x1)/2 - width_current_text/2), height_current_text*2), cv2.FONT_HERSHEY_SIMPLEX, fontscale_current_text, (0, 0, 255), thickness_current_text)
        cv2.namedWindow(&#39;Screencapture Preview&#39;, cv2.WINDOW_NORMAL)
        cv2.setWindowProperty(&#39;Screencapture Preview&#39;, cv2.WND_PROP_TOPMOST, 1)
        cv2.resizeWindow(&#39;Screencapture Preview&#39;, round((x2-x1)/2), round((y2-y1)/2))
        cv2.imshow(&#39;Screencapture Preview&#39;, screenshot)
        cv2.waitKey(1)
        
    def screencapture_close():
        try: 
            cv2.destroyWindow(&#39;Screencapture Preview&#39;)
        except: 
            pass

    self.windowwidthSlider = tk.Scale(outputwindowFrame, from_=round(screen_width/20), to=screen_width, resolution=1, orient=tk.HORIZONTAL, length=480, command=lambda x: self.UpdateSliderValue_windowwidth())
    self.windowwidthSlider.set(settings.GetSettings(&#34;TrafficLightDetection&#34;, &#34;outputwindowwidth&#34;, round(screen_width/2)))
    self.windowwidthSlider.grid(row=6, column=0, padx=10, pady=0, columnspan=2)
    self.windowwidth = helpers.MakeComboEntry(outputwindowFrame, &#34;Window Width&#34;, &#34;TrafficLightDetection&#34;, &#34;outputwindowwidth&#34;, 6,0, labelwidth=13, width=10)

    self.windowheightSlider = tk.Scale(outputwindowFrame, from_=round(screen_height/20), to=screen_height, resolution=1, orient=tk.HORIZONTAL, length=480, command=lambda x: self.UpdateSliderValue_windowheight())
    self.windowheightSlider.set(settings.GetSettings(&#34;TrafficLightDetection&#34;, &#34;outputwindowheight&#34;, round(screen_height/3)))
    self.windowheightSlider.grid(row=7, column=0, padx=10, pady=0, columnspan=2)
    self.windowheight = helpers.MakeComboEntry(outputwindowFrame, &#34;Window Height&#34;, &#34;TrafficLightDetection&#34;, &#34;outputwindowheight&#34;, 7,0, labelwidth=13, width=10)

    self.scaleSlider = tk.Scale(outputwindowFrame, from_=0.1, to=2, resolution=0.01, orient=tk.HORIZONTAL, length=480, command=lambda x: self.UpdateSliderValue_scale())
    self.scaleSlider.set(settings.GetSettings(&#34;TrafficLightDetection&#34;, &#34;scale&#34;, 0.5))
    self.scaleSlider.grid(row=8, column=0, padx=10, pady=0, columnspan=2)
    self.scale = helpers.MakeComboEntry(outputwindowFrame, &#34;Window Scale&#34;, &#34;TrafficLightDetection&#34;, &#34;scale&#34;, 8,0, labelwidth=13, width=10)

    self.minrectsizeSlider = tk.Scale(filtersFrame, from_=1, to=round(screen_width / 2), resolution=1, orient=tk.HORIZONTAL, length=700, command=lambda x: self.UpdateSliderValue_minrectsize())
    self.minrectsizeSlider.set(settings.GetSettings(&#34;TrafficLightDetection&#34;, &#34;minrectsize&#34;, round(screen_width / 240)))
    self.minrectsizeSlider.grid(row=7, column=0, padx=10, pady=0, columnspan=2)
    self.minrectsize = helpers.MakeComboEntry(filtersFrame, &#34;Min. Traffic Light Size Filter&#34;, &#34;TrafficLightDetection&#34;, &#34;minrectsize&#34;, 8,0, labelwidth=80, width=20)

    self.maxrectsizeSlider = tk.Scale(filtersFrame, from_=1, to=round(screen_width / 2), resolution=1, orient=tk.HORIZONTAL, length=700, command=lambda x: self.UpdateSliderValue_maxrectsize())
    self.maxrectsizeSlider.set(settings.GetSettings(&#34;TrafficLightDetection&#34;, &#34;maxrectsize&#34;, round(screen_width / 10)))
    self.maxrectsizeSlider.grid(row=9, column=0, padx=10, pady=0, columnspan=2)
    self.maxrectsize = helpers.MakeComboEntry(filtersFrame, &#34;Max. Traffic Light Size Filter&#34;, &#34;TrafficLightDetection&#34;, &#34;maxrectsize&#34;, 10,0, labelwidth=80, width=20)

    self.upperredr = helpers.MakeComboEntry(colorsettingsFrame, &#34;RED:         Upper R:&#34;, &#34;TrafficLightDetection&#34;, &#34;upperred_r&#34;, 2, 0, labelwidth=20, width=7)
    self.upperredg = helpers.MakeComboEntry(colorsettingsFrame, &#34;Upper G:&#34;, &#34;TrafficLightDetection&#34;, &#34;upperred_g&#34;, 2, 2, labelwidth=13, width=7)
    self.upperredb = helpers.MakeComboEntry(colorsettingsFrame, &#34;Upper B:&#34;, &#34;TrafficLightDetection&#34;, &#34;upperred_b&#34;, 2, 4, labelwidth=13, width=7)
    self.lowerredr = helpers.MakeComboEntry(colorsettingsFrame, &#34;RED:         Lower R:&#34;, &#34;TrafficLightDetection&#34;, &#34;lowerred_r&#34;, 3, 0, labelwidth=20, width=7)
    self.lowerredg = helpers.MakeComboEntry(colorsettingsFrame, &#34;Lower G:&#34;, &#34;TrafficLightDetection&#34;, &#34;lowerred_g&#34;, 3, 2, labelwidth=13, width=7)
    self.lowerredb = helpers.MakeComboEntry(colorsettingsFrame, &#34;Lower B:&#34;, &#34;TrafficLightDetection&#34;, &#34;lowerred_b&#34;, 3, 4, labelwidth=13, width=7)
    self.upperyellowr = helpers.MakeComboEntry(colorsettingsFrame, &#34;YELLOW:  Upper R:&#34;, &#34;TrafficLightDetection&#34;, &#34;upperyellow_r&#34;, 4, 0, labelwidth=20, width=7)
    self.upperyellowg = helpers.MakeComboEntry(colorsettingsFrame, &#34;Upper G:&#34;, &#34;TrafficLightDetection&#34;, &#34;upperyellow_g&#34;, 4, 2, labelwidth=13, width=7)
    self.upperyellowb = helpers.MakeComboEntry(colorsettingsFrame, &#34;Upper B:&#34;, &#34;TrafficLightDetection&#34;, &#34;upperyellow_b&#34;, 4, 4, labelwidth=13, width=7)
    self.loweryellowr = helpers.MakeComboEntry(colorsettingsFrame, &#34;YELLOW:  Lower R:&#34;, &#34;TrafficLightDetection&#34;, &#34;loweryellow_r&#34;, 5, 0, labelwidth=20, width=7)
    self.loweryellowg = helpers.MakeComboEntry(colorsettingsFrame, &#34;Lower G:&#34;, &#34;TrafficLightDetection&#34;, &#34;loweryellow_g&#34;, 5, 2, labelwidth=13, width=7)
    self.loweryellowb = helpers.MakeComboEntry(colorsettingsFrame, &#34;Lower B:&#34;, &#34;TrafficLightDetection&#34;, &#34;loweryellow_b&#34;, 5, 4, labelwidth=13, width=7)
    self.uppergreenr = helpers.MakeComboEntry(colorsettingsFrame, &#34;GREEN:    Upper R:&#34;, &#34;TrafficLightDetection&#34;, &#34;uppergreen_r&#34;, 6, 0, labelwidth=20, width=7)
    self.uppergreeng = helpers.MakeComboEntry(colorsettingsFrame, &#34;Upper G:&#34;, &#34;TrafficLightDetection&#34;, &#34;uppergreen_g&#34;, 6, 2, labelwidth=13, width=7)
    self.uppergreenb = helpers.MakeComboEntry(colorsettingsFrame, &#34;Upper B:&#34;, &#34;TrafficLightDetection&#34;, &#34;uppergreen_b&#34;, 6, 4, labelwidth=13, width=7)
    self.lowergreenr = helpers.MakeComboEntry(colorsettingsFrame, &#34;GREEN:    Lower R:&#34;, &#34;TrafficLightDetection&#34;, &#34;lowergreen_r&#34;, 7, 0, labelwidth=20, width=7)
    self.lowergreeng = helpers.MakeComboEntry(colorsettingsFrame, &#34;Lower G:&#34;, &#34;TrafficLightDetection&#34;, &#34;lowergreen_g&#34;, 7, 2, labelwidth=13, width=7)
    self.lowergreenb = helpers.MakeComboEntry(colorsettingsFrame, &#34;Lower B:&#34;, &#34;TrafficLightDetection&#34;, &#34;lowergreen_b&#34;, 7, 4, labelwidth=13, width=7)
    helpers.MakeButton(colorsettingsFrame, &#34;Save&#34;, command=self.save, row=15, column=0, sticky=&#34;w&#34;)

    helpers.MakeLabel(colorsettingsFrame, &#34;&#34;, 13, 0, columnspan=7)
    helpers.MakeLabel(colorsettingsFrame, &#34;&#34;, 14, 0, columnspan=7)
    helpers.MakeButton(colorsettingsFrame, &#34;Reset&#34;, command=self.resetadvancedcolorstodefault, row=15, column=5)
    helpers.MakeEmptyLine(colorsettingsFrame,12,1)
    helpers.MakeEmptyLine(colorsettingsFrame,13,1)
    helpers.MakeEmptyLine(colorsettingsFrame,14,1)
    helpers.MakeButton(filtersFrame, &#34;Reset&#34;, command=self.resetadvancedfilterstodefault, row=15, column=1, width=20)
    helpers.MakeEmptyLine(filtersFrame,14,1)
    helpers.MakeButton(generalFrame, &#34;Reset Advanced Settings\nto Default\n------------------------------------&#34;, command=self.resetalladvancedsettingstodefault, row=6, column=1, width=32,)</code></pre>
</details>
</dd>
<dt id="Euro-Truck-Simulator-2-Lane-Assist.plugins.TrafficLightDetection.main.UI.resetadvancedcolorstodefault"><code class="name flex">
<span>def <span class="ident">resetadvancedcolorstodefault</span></span>(<span>self)</span>
</code></dt>
<dd>
<div class="desc"></div>
<details class="source">
<summary>
<span>Expand source code</span>
</summary>
<pre><code class="python">def resetadvancedcolorstodefault(self):
    settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;upperred_r&#34;, 255)
    settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;upperred_g&#34;, 110)
    settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;upperred_b&#34;, 110)
    settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;lowerred_r&#34;, 200)
    settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;lowerred_g&#34;, 0)
    settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;lowerred_b&#34;, 0)
    settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;upperyellow_r&#34;, 255)
    settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;upperyellow_g&#34;, 240)
    settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;upperyellow_b&#34;, 170)
    settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;loweryellow_r&#34;, 200)
    settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;loweryellow_g&#34;, 170)
    settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;loweryellow_b&#34;, 50)
    settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;uppergreen_r&#34;, 150)
    settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;uppergreen_g&#34;, 255)
    settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;uppergreen_b&#34;, 230)
    settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;lowergreen_r&#34;, 0)
    settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;lowergreen_g&#34;, 200)
    settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;lowergreen_b&#34;, 0)
    self.upperredr.set(255)
    self.upperredg.set(110)
    self.upperredb.set(110)
    self.lowerredr.set(200)
    self.lowerredg.set(0)
    self.lowerredb.set(0)
    self.upperyellowr.set(255)
    self.upperyellowg.set(240)
    self.upperyellowb.set(170)
    self.loweryellowr.set(200)
    self.loweryellowg.set(170)
    self.loweryellowb.set(50)
    self.uppergreenr.set(150)
    self.uppergreeng.set(255)
    self.uppergreenb.set(230)
    self.lowergreenr.set(0)
    self.lowergreeng.set(200)
    self.lowergreenb.set(0)
    UpdateSettings()</code></pre>
</details>
</dd>
<dt id="Euro-Truck-Simulator-2-Lane-Assist.plugins.TrafficLightDetection.main.UI.resetadvancedfilterstodefault"><code class="name flex">
<span>def <span class="ident">resetadvancedfilterstodefault</span></span>(<span>self)</span>
</code></dt>
<dd>
<div class="desc"></div>
<details class="source">
<summary>
<span>Expand source code</span>
</summary>
<pre><code class="python">def resetadvancedfilterstodefault(self):
    settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;rectsizefilter&#34;, True)
    settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;widthheightratiofilter&#34;, True)
    settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;pixelpercentagefilter&#34;, True)
    settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;otherlightsofffilter&#34;, True)

    settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;minrectsize&#34;, round(screen_width / 240))
    settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;maxrectsize&#34;, round(screen_width / 10))
    self.minrectsizeSlider.set(round(screen_width / 240))
    self.minrectsize.set(round(screen_width / 240))
    self.maxrectsizeSlider.set(round(screen_width / 10))
    self.maxrectsize.set(round(screen_width / 10))
    self.exampleFunction()
    UpdateSettings()</code></pre>
</details>
</dd>
<dt id="Euro-Truck-Simulator-2-Lane-Assist.plugins.TrafficLightDetection.main.UI.resetalladvancedsettingstodefault"><code class="name flex">
<span>def <span class="ident">resetalladvancedsettingstodefault</span></span>(<span>self)</span>
</code></dt>
<dd>
<div class="desc"></div>
<details class="source">
<summary>
<span>Expand source code</span>
</summary>
<pre><code class="python">def resetalladvancedsettingstodefault(self):
    settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;rectsizefilter&#34;, True)
    settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;widthheightratiofilter&#34;, True)
    settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;pixelpercentagefilter&#34;, True)
    settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;otherlightsofffilter&#34;, True)

    settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;minrectsize&#34;, round(screen_width / 240))
    settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;maxrectsize&#34;, round(screen_width / 10))

    settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;upperred_r&#34;, 255)
    settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;upperred_g&#34;, 110)
    settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;upperred_b&#34;, 110)
    settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;lowerred_r&#34;, 200)
    settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;lowerred_g&#34;, 0)
    settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;lowerred_b&#34;, 0)
    settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;upperyellow_r&#34;, 255)
    settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;upperyellow_g&#34;, 240)
    settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;upperyellow_b&#34;, 170)
    settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;loweryellow_r&#34;, 200)
    settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;loweryellow_g&#34;, 170)
    settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;loweryellow_b&#34;, 50)
    settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;uppergreen_r&#34;, 150)
    settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;uppergreen_g&#34;, 255)
    settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;uppergreen_b&#34;, 230)
    settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;lowergreen_r&#34;, 0)
    settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;lowergreen_g&#34;, 200)
    settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;lowergreen_b&#34;, 0)
    self.upperredr.set(255)
    self.upperredg.set(110)
    self.upperredb.set(110)
    self.lowerredr.set(200)
    self.lowerredg.set(0)
    self.lowerredb.set(0)
    self.upperyellowr.set(255)
    self.upperyellowg.set(240)
    self.upperyellowb.set(170)
    self.loweryellowr.set(200)
    self.loweryellowg.set(170)
    self.loweryellowb.set(50)
    self.uppergreenr.set(150)
    self.uppergreeng.set(255)
    self.uppergreenb.set(230)
    self.lowergreenr.set(0)
    self.lowergreeng.set(200)
    self.lowergreenb.set(0)
    self.exampleFunction()
    UpdateSettings()</code></pre>
</details>
</dd>
<dt id="Euro-Truck-Simulator-2-Lane-Assist.plugins.TrafficLightDetection.main.UI.save"><code class="name flex">
<span>def <span class="ident">save</span></span>(<span>self)</span>
</code></dt>
<dd>
<div class="desc"></div>
<details class="source">
<summary>
<span>Expand source code</span>
</summary>
<pre><code class="python">def save(self):
    
    try:
        self.upperredr.get()
    except:
        self.upperredr.set(255)
    try:
        self.upperredg.get()
    except:
        self.upperredg.set(110)
    try:
        self.upperredb.get()
    except:
        self.upperredb.set(110)
    try:
        self.lowerredr.get()
    except:
        self.lowerredr.set(200)
    try:
        self.lowerredg.get()
    except:
        self.lowerredg.set(0)
    try:
        self.lowerredb.get()
    except:
        self.lowerredb.set(0)
    try:
        self.upperyellowr.get()
    except:
        self.upperyellowr.set(255)
    try:
        self.upperyellowg.get()
    except:
        self.upperyellowg.set(240)
    try:
        self.upperyellowb.get()
    except:
        self.upperyellowb.set(170)
    try:
        self.loweryellowr.get()
    except:
        self.loweryellowr.set(200)
    try:
        self.loweryellowg.get()
    except:
        self.loweryellowg.set(170)
    try:
        self.loweryellowb.get()
    except:
        self.loweryellowb.set(50)
    try:
        self.uppergreenr.get()
    except:
        self.uppergreenr.set(150)
    try:
        self.uppergreeng.get()
    except:
        self.uppergreeng.set(255)
    try:
        self.uppergreenb.get()
    except:
        self.uppergreenb.set(230)
    try:
        self.lowergreenr.get()
    except:
        self.lowergreenr.set(0)
    try:
        self.lowergreeng.get()
    except:
        self.lowergreeng.set(200)
    try:
        self.lowergreenb.get()
    except:
        self.lowergreenb.set(0)
    if not (0 &lt;= self.upperredr.get() &lt;= 255):
        self.upperredr.set(255)
    if not (0 &lt;= self.upperredg.get() &lt;= 255):
        self.upperredg.set(110)
    if not (0 &lt;= self.upperredb.get() &lt;= 255):
        self.upperredb.set(110)
    if not (0 &lt;= self.lowerredr.get() &lt;= 255):
        self.lowerredr.set(200)  
    if not (0 &lt;= self.lowerredg.get() &lt;= 255):
        self.lowerredg.set(0)
    if not (0 &lt;= self.lowerredb.get() &lt;= 255):
        self.lowerredb.set(0)
    if not (0 &lt;= self.upperyellowr.get() &lt;= 255):
        self.upperyellowr.set(255)
    if not (0 &lt;= self.upperyellowg.get() &lt;= 255):
        self.upperyellowg.set(240)
    if not (0 &lt;= self.upperyellowb.get() &lt;= 255):
        self.upperyellowb.set(170)
    if not (0 &lt;= self.loweryellowr.get() &lt;= 255):
        self.loweryellowr.set(200)
    if not (0 &lt;= self.loweryellowg.get() &lt;= 255):
        self.loweryellowg.set(170)
    if not (0 &lt;= self.loweryellowb.get() &lt;= 255):
        self.loweryellowb.set(50)
    if not (0 &lt;= self.uppergreenr.get() &lt;= 255):
        self.uppergreenr.set(150)
    if not (0 &lt;= self.uppergreeng.get() &lt;= 255):
        self.uppergreeng.set(255)
    if not (0 &lt;= self.uppergreenb.get() &lt;= 255):
        self.uppergreenb.set(230)
    if not (0 &lt;= self.lowergreenr.get() &lt;= 255):
        self.lowergreenr.set(0)
    if not (0 &lt;= self.lowergreeng.get() &lt;= 255):
        self.lowergreeng.set(200)
    if not (0 &lt;= self.lowergreenb.get() &lt;= 255):
        self.lowergreenb.set(0)
    settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;upperred_r&#34;, self.upperredr.get())
    settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;upperred_g&#34;, self.upperredg.get())
    settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;upperred_b&#34;, self.upperredb.get())
    settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;lowerred_r&#34;, self.lowerredr.get())
    settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;lowerred_g&#34;, self.lowerredg.get())
    settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;lowerred_b&#34;, self.lowerredb.get())
    settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;upperyellow_r&#34;, self.upperyellowr.get())
    settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;upperyellow_g&#34;, self.upperyellowg.get())
    settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;upperyellow_b&#34;, self.upperyellowb.get())
    settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;loweryellow_r&#34;, self.loweryellowr.get())
    settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;loweryellow_g&#34;, self.loweryellowg.get())
    settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;loweryellow_b&#34;, self.loweryellowb.get())
    settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;uppergreen_r&#34;, self.uppergreenr.get())
    settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;uppergreen_g&#34;, self.uppergreeng.get())
    settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;uppergreen_b&#34;, self.uppergreenb.get())
    settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;lowergreen_r&#34;, self.lowergreenr.get())
    settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;lowergreen_g&#34;, self.lowergreeng.get())
    settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;lowergreen_b&#34;, self.lowergreenb.get())
    UpdateSettings()</code></pre>
</details>
</dd>
<dt id="Euro-Truck-Simulator-2-Lane-Assist.plugins.TrafficLightDetection.main.UI.save_and_load_model"><code class="name flex">
<span>def <span class="ident">save_and_load_model</span></span>(<span>self)</span>
</code></dt>
<dd>
<div class="desc"></div>
<details class="source">
<summary>
<span>Expand source code</span>
</summary>
<pre><code class="python">def save_and_load_model(self):
    global yolo_model_loaded
    yolo_model_loaded = False
    settings.CreateSettings(&#34;TrafficLightDetection&#34;, &#34;yolo_model&#34;, self.model_ui)
    loadYOLO()
    UpdateSettings()</code></pre>
</details>
</dd>
<dt id="Euro-Truck-Simulator-2-Lane-Assist.plugins.TrafficLightDetection.main.UI.tabFocused"><code class="name flex">
<span>def <span class="ident">tabFocused</span></span>(<span>self)</span>
</code></dt>
<dd>
<div class="desc"></div>
<details class="source">
<summary>
<span>Expand source code</span>
</summary>
<pre><code class="python">def tabFocused(self):
    resizeWindow(850,600)</code></pre>
</details>
</dd>
<dt id="Euro-Truck-Simulator-2-Lane-Assist.plugins.TrafficLightDetection.main.UI.update"><code class="name flex">
<span>def <span class="ident">update</span></span>(<span>self, data)</span>
</code></dt>
<dd>
<div class="desc"></div>
<details class="source">
<summary>
<span>Expand source code</span>
</summary>
<pre><code class="python">def update(self, data): 
    self.root.update()</code></pre>
</details>
</dd>
</dl>
</dd>
</dl>
</section>
</article>
<nav id="sidebar">
<h1>Index</h1>
<div class="toc">
<ul></ul>
</div>
<ul id="index">
<li><h3>Super-module</h3>
<ul>
<li><code><a title="Euro-Truck-Simulator-2-Lane-Assist.plugins.TrafficLightDetection" href="index.html">Euro-Truck-Simulator-2-Lane-Assist.plugins.TrafficLightDetection</a></code></li>
</ul>
</li>
<li><h3><a href="#header-functions">Functions</a></h3>
<ul class="">
<li><code><a title="Euro-Truck-Simulator-2-Lane-Assist.plugins.TrafficLightDetection.main.UpdateSettings" href="#Euro-Truck-Simulator-2-Lane-Assist.plugins.TrafficLightDetection.main.UpdateSettings">UpdateSettings</a></code></li>
<li><code><a title="Euro-Truck-Simulator-2-Lane-Assist.plugins.TrafficLightDetection.main.loadYOLO" href="#Euro-Truck-Simulator-2-Lane-Assist.plugins.TrafficLightDetection.main.loadYOLO">loadYOLO</a></code></li>
<li><code><a title="Euro-Truck-Simulator-2-Lane-Assist.plugins.TrafficLightDetection.main.onDisable" href="#Euro-Truck-Simulator-2-Lane-Assist.plugins.TrafficLightDetection.main.onDisable">onDisable</a></code></li>
<li><code><a title="Euro-Truck-Simulator-2-Lane-Assist.plugins.TrafficLightDetection.main.onEnable" href="#Euro-Truck-Simulator-2-Lane-Assist.plugins.TrafficLightDetection.main.onEnable">onEnable</a></code></li>
<li><code><a title="Euro-Truck-Simulator-2-Lane-Assist.plugins.TrafficLightDetection.main.plugin" href="#Euro-Truck-Simulator-2-Lane-Assist.plugins.TrafficLightDetection.main.plugin">plugin</a></code></li>
<li><code><a title="Euro-Truck-Simulator-2-Lane-Assist.plugins.TrafficLightDetection.main.yolo_detection_function" href="#Euro-Truck-Simulator-2-Lane-Assist.plugins.TrafficLightDetection.main.yolo_detection_function">yolo_detection_function</a></code></li>
</ul>
</li>
<li><h3><a href="#header-classes">Classes</a></h3>
<ul>
<li>
<h4><code><a title="Euro-Truck-Simulator-2-Lane-Assist.plugins.TrafficLightDetection.main.UI" href="#Euro-Truck-Simulator-2-Lane-Assist.plugins.TrafficLightDetection.main.UI">UI</a></code></h4>
<ul class="">
<li><code><a title="Euro-Truck-Simulator-2-Lane-Assist.plugins.TrafficLightDetection.main.UI.UpdateSliderValue_maxrectsize" href="#Euro-Truck-Simulator-2-Lane-Assist.plugins.TrafficLightDetection.main.UI.UpdateSliderValue_maxrectsize">UpdateSliderValue_maxrectsize</a></code></li>
<li><code><a title="Euro-Truck-Simulator-2-Lane-Assist.plugins.TrafficLightDetection.main.UI.UpdateSliderValue_minrectsize" href="#Euro-Truck-Simulator-2-Lane-Assist.plugins.TrafficLightDetection.main.UI.UpdateSliderValue_minrectsize">UpdateSliderValue_minrectsize</a></code></li>
<li><code><a title="Euro-Truck-Simulator-2-Lane-Assist.plugins.TrafficLightDetection.main.UI.UpdateSliderValue_scale" href="#Euro-Truck-Simulator-2-Lane-Assist.plugins.TrafficLightDetection.main.UI.UpdateSliderValue_scale">UpdateSliderValue_scale</a></code></li>
<li><code><a title="Euro-Truck-Simulator-2-Lane-Assist.plugins.TrafficLightDetection.main.UI.UpdateSliderValue_windowheight" href="#Euro-Truck-Simulator-2-Lane-Assist.plugins.TrafficLightDetection.main.UI.UpdateSliderValue_windowheight">UpdateSliderValue_windowheight</a></code></li>
<li><code><a title="Euro-Truck-Simulator-2-Lane-Assist.plugins.TrafficLightDetection.main.UI.UpdateSliderValue_windowwidth" href="#Euro-Truck-Simulator-2-Lane-Assist.plugins.TrafficLightDetection.main.UI.UpdateSliderValue_windowwidth">UpdateSliderValue_windowwidth</a></code></li>
<li><code><a title="Euro-Truck-Simulator-2-Lane-Assist.plugins.TrafficLightDetection.main.UI.UpdateSliderValue_x1ofsc" href="#Euro-Truck-Simulator-2-Lane-Assist.plugins.TrafficLightDetection.main.UI.UpdateSliderValue_x1ofsc">UpdateSliderValue_x1ofsc</a></code></li>
<li><code><a title="Euro-Truck-Simulator-2-Lane-Assist.plugins.TrafficLightDetection.main.UI.UpdateSliderValue_x2ofsc" href="#Euro-Truck-Simulator-2-Lane-Assist.plugins.TrafficLightDetection.main.UI.UpdateSliderValue_x2ofsc">UpdateSliderValue_x2ofsc</a></code></li>
<li><code><a title="Euro-Truck-Simulator-2-Lane-Assist.plugins.TrafficLightDetection.main.UI.UpdateSliderValue_y1ofsc" href="#Euro-Truck-Simulator-2-Lane-Assist.plugins.TrafficLightDetection.main.UI.UpdateSliderValue_y1ofsc">UpdateSliderValue_y1ofsc</a></code></li>
<li><code><a title="Euro-Truck-Simulator-2-Lane-Assist.plugins.TrafficLightDetection.main.UI.UpdateSliderValue_y2ofsc" href="#Euro-Truck-Simulator-2-Lane-Assist.plugins.TrafficLightDetection.main.UI.UpdateSliderValue_y2ofsc">UpdateSliderValue_y2ofsc</a></code></li>
<li><code><a title="Euro-Truck-Simulator-2-Lane-Assist.plugins.TrafficLightDetection.main.UI.destroy" href="#Euro-Truck-Simulator-2-Lane-Assist.plugins.TrafficLightDetection.main.UI.destroy">destroy</a></code></li>
<li><code><a title="Euro-Truck-Simulator-2-Lane-Assist.plugins.TrafficLightDetection.main.UI.exampleFunction" href="#Euro-Truck-Simulator-2-Lane-Assist.plugins.TrafficLightDetection.main.UI.exampleFunction">exampleFunction</a></code></li>
<li><code><a title="Euro-Truck-Simulator-2-Lane-Assist.plugins.TrafficLightDetection.main.UI.resetadvancedcolorstodefault" href="#Euro-Truck-Simulator-2-Lane-Assist.plugins.TrafficLightDetection.main.UI.resetadvancedcolorstodefault">resetadvancedcolorstodefault</a></code></li>
<li><code><a title="Euro-Truck-Simulator-2-Lane-Assist.plugins.TrafficLightDetection.main.UI.resetadvancedfilterstodefault" href="#Euro-Truck-Simulator-2-Lane-Assist.plugins.TrafficLightDetection.main.UI.resetadvancedfilterstodefault">resetadvancedfilterstodefault</a></code></li>
<li><code><a title="Euro-Truck-Simulator-2-Lane-Assist.plugins.TrafficLightDetection.main.UI.resetalladvancedsettingstodefault" href="#Euro-Truck-Simulator-2-Lane-Assist.plugins.TrafficLightDetection.main.UI.resetalladvancedsettingstodefault">resetalladvancedsettingstodefault</a></code></li>
<li><code><a title="Euro-Truck-Simulator-2-Lane-Assist.plugins.TrafficLightDetection.main.UI.save" href="#Euro-Truck-Simulator-2-Lane-Assist.plugins.TrafficLightDetection.main.UI.save">save</a></code></li>
<li><code><a title="Euro-Truck-Simulator-2-Lane-Assist.plugins.TrafficLightDetection.main.UI.save_and_load_model" href="#Euro-Truck-Simulator-2-Lane-Assist.plugins.TrafficLightDetection.main.UI.save_and_load_model">save_and_load_model</a></code></li>
<li><code><a title="Euro-Truck-Simulator-2-Lane-Assist.plugins.TrafficLightDetection.main.UI.tabFocused" href="#Euro-Truck-Simulator-2-Lane-Assist.plugins.TrafficLightDetection.main.UI.tabFocused">tabFocused</a></code></li>
<li><code><a title="Euro-Truck-Simulator-2-Lane-Assist.plugins.TrafficLightDetection.main.UI.update" href="#Euro-Truck-Simulator-2-Lane-Assist.plugins.TrafficLightDetection.main.UI.update">update</a></code></li>
</ul>
</li>
</ul>
</li>
</ul>
</nav>
</main>
<footer id="footer">
<p>Generated by <a href="https://pdoc3.github.io/pdoc"><cite>pdoc</cite> 0.10.0</a>.</p>
</footer>
</body>
</html>